### Hollibaugh and Krause
rm(list=ls())
library(haven)
library(Amelia)
library(effects)
library(ggplot2)
library(reshape2)
library(MplusAutomation)
library(MASS)
library(KRLS)
library(plyr)
library(dplyr)
library(Zelig)
library(ZeligChoice)
library(VGAM) # for testing PO assumptions
library(texreg)
library(nnet)
library(lmtest)
library(scales)
library(gtools)
library(car)



setwd("~/Dropbox/Offline Hollibaugh and Krause") 
source('HK-extract-polr.R')
source('HK-extract-pooled-ologit.R')
source('HK-extract-krls.R')
source('HK-extract-krls-quantiles.R')
source('HK-extract-krls-pooled.R')
source("HK-extract-krls-quantiles-pooled.R")
source("HK-extract-multinom.R")


# Load in the data
repfile <- readRDS(file = "HK-JPIPE.rds")



### checks on loyalty-competence tradeoff w/r/t reliability (-1 = substitute, 1 = complement)
with(subset(repfile, fealtyboth.tercile.ols != 0), cor.test(policy.mean, fealty.ols.mean))
with(subset(repfile, fealtyboth.tercile.efa != 0), cor.test(policy.mean, fealty.efa.mean))
with(subset(repfile, fealtyboth.tercile.ols != 0), cor.test(managerial.mean, fealty.ols.mean))
with(subset(repfile, fealtyboth.tercile.efa != 0), cor.test(managerial.mean, fealty.efa.mean))

with(subset(repfile, fealtyboth.tercile.ols != 0), cor.test(policy.mean, zpresnomdist))
with(subset(repfile, fealtyboth.tercile.efa != 0), cor.test(policy.mean, zpresnomdist))
with(subset(repfile, fealtyboth.tercile.ols != 0), cor.test(managerial.mean, zpresnomdist))
with(subset(repfile, fealtyboth.tercile.efa != 0), cor.test(managerial.mean, zpresnomdist))



# estimating models!
ologit.ols.tercile.fil.mod <- polr(factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.fil.mod <- polr(factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.ols.tercile.fil.mod.nodivided <- polr(factor(fealtyboth.tercile.ols) ~ (zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.fil.mod.nodivided <- polr(factor(fealtyboth.tercile.efa) ~ (zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)

ologit.ols.tercile.median.mod <- polr(factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.median.mod <- polr(factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.ols.tercile.median.mod.nodivided <- polr(factor(fealtyboth.tercile.ols) ~ (zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.median.mod.nodivided <- polr(factor(fealtyboth.tercile.efa) ~ (zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)

ologit.ols.tercile.chair.mod <- polr(factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.chair.mod <- polr(factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.ols.tercile.chair.mod.nodivided <- polr(factor(fealtyboth.tercile.ols) ~ (zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.chair.mod.nodivided <- polr(factor(fealtyboth.tercile.efa) ~ (zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)

ologit.ols.tercile.comm.mod <- polr(factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.comm.mod <- polr(factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.ols.tercile.comm.mod.nodivided <- polr(factor(fealtyboth.tercile.ols) ~ (zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)
ologit.efa.tercile.comm.mod.nodivided <- polr(factor(fealtyboth.tercile.efa) ~ (zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile)


htmlreg(file = "Table-A9.doc",
        list(extract.polr(ologit.ols.tercile.median.mod),
             extract.polr(ologit.efa.tercile.median.mod), 
             extract.polr(ologit.ols.tercile.fil.mod), 
             extract.polr(ologit.efa.tercile.fil.mod)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Senate Median Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2",
                              "President-Filibuster Pivot Ideological Divergence",
                              "President-Filibuster Pivot Ideological Divergence x Divided Government"),
        reorder.coef = c(2, 15, 3, 1, 10, 11, 16, 12, 6, 7, 5, 8, 9, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores (Median)", "EFA-Based Scores (Median)", 
                               "OLS-Based Scores (Filibuster)", "EFA-Based Scores (Filibuster)"))


htmlreg(file = "Table-A10.doc",
        list(extract.polr(ologit.ols.tercile.chair.mod),
             extract.polr(ologit.efa.tercile.chair.mod), 
             extract.polr(ologit.ols.tercile.comm.mod), 
             extract.polr(ologit.efa.tercile.comm.mod)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Committee Chair Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Committee Chair Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2",
                              "President-Committee Median Ideological Divergence",
                              "President-Committee Median Ideological Divergence x Divided Government"),
        reorder.coef = c(2, 15, 3, 1, 10, 11, 16, 12, 6, 7, 5, 8, 9, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores (Chair)", "EFA-Based Scores (Chair)", 
                               "OLS-Based Scores (Committee)", "EFA-Based Scores (Committee)"))



# Function to create sequence from minimum to maximum with knots at 25th/50th/75th percentiles
seq_alt <- function(x){
  seq.foo <- c(seq(min(x, na.rm = T), as.numeric(quantile(unique(x), 1/4, na.rm = T)), length.out = 25),
               seq(as.numeric(quantile(unique(x), 1/4, na.rm = T)), as.numeric(quantile(unique(x), 1/2, na.rm = T)), length.out = 26)[-1],
               seq(as.numeric(quantile(unique(x), 1/2, na.rm = T)), as.numeric(quantile(unique(x), 3/4, na.rm = T)), length.out = 26)[-1],
               seq(as.numeric(quantile(unique(x), 3/4, na.rm = T)), max(x, na.rm = T), length.out = 26)[-1])
  
  seq.foo <- lowess(seq.foo)$y
  return(scales::rescale(seq.foo, to = c(min(x, na.rm = T), max(x, na.rm = T))))
}

seq_alt_unified_med <- seq_alt(unique(subset(repfile, dividedpressenate == 0, select = c(zpressendist))$zpressendist))  
seq_alt_divided_med <- seq_alt(unique(subset(repfile, dividedpressenate == 1, select = c(zpressendist))$zpressendist))  

seq_alt_unified_fil <- seq_alt(unique(subset(repfile, dividedpressenate == 0, select = c(zpresfildist))$zpresfildist))  
seq_alt_divided_fil <- seq_alt(unique(subset(repfile, dividedpressenate == 1, select = c(zpresfildist))$zpresfildist))  

seq_alt_unified_com <- seq_alt(unique(subset(repfile, dividedpressenate == 0, select = c(zprescommdist))$zprescommdist))  
seq_alt_divided_com <- seq_alt(unique(subset(repfile, dividedpressenate == 1, select = c(zprescommdist))$zprescommdist))  

seq_alt_unified_cha <- seq_alt(unique(subset(repfile, dividedpressenate == 0, select = c(zpreschairdist))$zpreschairdist))  
seq_alt_divided_cha <- seq_alt(unique(subset(repfile, dividedpressenate == 1, select = c(zpreschairdist))$zpreschairdist))  

zelig.tercile.median.ols <- zelig(fealtyboth.tercile.ols ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.median.efa <- zelig(fealtyboth.tercile.efa ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.median.ols.unified.setx <- setx(zelig.tercile.median.ols, zpressendist = seq_alt_unified_med, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.median.ols.divided.setx <- setx(zelig.tercile.median.ols, zpressendist = seq_alt_divided_med, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.median.efa.unified.setx <- setx(zelig.tercile.median.efa, zpressendist = seq_alt_unified_med, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.median.efa.divided.setx <- setx(zelig.tercile.median.efa, zpressendist = seq_alt_divided_med, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)

zelig.tercile.fil.ols <- zelig(fealtyboth.tercile.ols ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.fil.efa <- zelig(fealtyboth.tercile.efa ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.fil.ols.unified.setx <- setx(zelig.tercile.fil.ols, zpresfildist = seq_alt_unified_fil, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.fil.ols.divided.setx <- setx(zelig.tercile.fil.ols, zpresfildist = seq_alt_divided_fil, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.fil.efa.unified.setx <- setx(zelig.tercile.fil.efa, zpresfildist = seq_alt_unified_fil, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.fil.efa.divided.setx <- setx(zelig.tercile.fil.efa, zpresfildist = seq_alt_divided_fil, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)

zelig.tercile.chair.ols <- zelig(fealtyboth.tercile.ols ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.chair.efa <- zelig(fealtyboth.tercile.efa ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.chair.ols.unified.setx <- setx(zelig.tercile.chair.ols, zpreschairdist = seq_alt_unified_cha, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.chair.ols.divided.setx <- setx(zelig.tercile.chair.ols, zpreschairdist = seq_alt_divided_cha, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.chair.efa.unified.setx <- setx(zelig.tercile.chair.efa, zpreschairdist = seq_alt_unified_cha, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.chair.efa.divided.setx <- setx(zelig.tercile.chair.efa, zpreschairdist = seq_alt_divided_cha, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)

zelig.tercile.comm.ols <- zelig(fealtyboth.tercile.ols ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.comm.efa <- zelig(fealtyboth.tercile.efa ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, data = repfile, model = "ologit")
zelig.tercile.comm.ols.unified.setx <- setx(zelig.tercile.comm.ols, zprescommdist = seq_alt_unified_com, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.comm.ols.divided.setx <- setx(zelig.tercile.comm.ols, zprescommdist = seq_alt_divided_com, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.comm.efa.unified.setx <- setx(zelig.tercile.comm.efa, zprescommdist = seq_alt_unified_com, dividedpressenate = 0, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)
zelig.tercile.comm.efa.divided.setx <- setx(zelig.tercile.comm.efa, zprescommdist = seq_alt_divided_com, dividedpressenate = 1, toplevel2 = 0, presalignedagency = 0, presopposedagency = 0, soucountagency1 = 1, approval = 55, policy.mean  = 0)


set.seed(1)
zelig.tercile.median.ols.unified.sims <- sim(obj = zelig.tercile.median.ols, x = zelig.tercile.median.ols.unified.setx, num = 10000)
zelig.tercile.median.ols.divided.sims <- sim(obj = zelig.tercile.median.ols, x = zelig.tercile.median.ols.divided.setx, num = 10000)
zelig.tercile.median.efa.unified.sims <- sim(obj = zelig.tercile.median.efa, x = zelig.tercile.median.efa.unified.setx, num = 10000)
zelig.tercile.median.efa.divided.sims <- sim(obj = zelig.tercile.median.efa, x = zelig.tercile.median.efa.divided.setx, num = 10000)

zelig.tercile.fil.ols.unified.sims <- sim(obj = zelig.tercile.fil.ols, x = zelig.tercile.fil.ols.unified.setx, num = 10000)
zelig.tercile.fil.ols.divided.sims <- sim(obj = zelig.tercile.fil.ols, x = zelig.tercile.fil.ols.divided.setx, num = 10000)
zelig.tercile.fil.efa.unified.sims <- sim(obj = zelig.tercile.fil.efa, x = zelig.tercile.fil.efa.unified.setx, num = 10000)
zelig.tercile.fil.efa.divided.sims <- sim(obj = zelig.tercile.fil.efa, x = zelig.tercile.fil.efa.divided.setx, num = 10000)

zelig.tercile.comm.ols.unified.sims <- sim(obj = zelig.tercile.comm.ols, x = zelig.tercile.comm.ols.unified.setx, num = 10000)
zelig.tercile.comm.ols.divided.sims <- sim(obj = zelig.tercile.comm.ols, x = zelig.tercile.comm.ols.divided.setx, num = 10000)
zelig.tercile.comm.efa.unified.sims <- sim(obj = zelig.tercile.comm.efa, x = zelig.tercile.comm.efa.unified.setx, num = 10000)
zelig.tercile.comm.efa.divided.sims <- sim(obj = zelig.tercile.comm.efa, x = zelig.tercile.comm.efa.divided.setx, num = 10000)

zelig.tercile.chair.ols.unified.sims <- sim(obj = zelig.tercile.chair.ols, x = zelig.tercile.chair.ols.unified.setx, num = 10000)
zelig.tercile.chair.ols.divided.sims <- sim(obj = zelig.tercile.chair.ols, x = zelig.tercile.chair.ols.divided.setx, num = 10000)
zelig.tercile.chair.efa.unified.sims <- sim(obj = zelig.tercile.chair.efa, x = zelig.tercile.chair.efa.unified.setx, num = 10000)
zelig.tercile.chair.efa.divided.sims <- sim(obj = zelig.tercile.chair.efa, x = zelig.tercile.chair.efa.divided.setx, num = 10000)


zelig.ols.median.unified.frame <- NULL
zelig.ols.median.divided.frame <- NULL
zelig.efa.median.unified.frame <- NULL
zelig.efa.median.divided.frame <- NULL

zelig.ols.fil.unified.frame <- NULL
zelig.ols.fil.divided.frame <- NULL
zelig.efa.fil.unified.frame <- NULL
zelig.efa.fil.divided.frame <- NULL

zelig.ols.chair.unified.frame <- NULL
zelig.ols.chair.divided.frame <- NULL
zelig.efa.chair.unified.frame <- NULL
zelig.efa.chair.divided.frame <- NULL

zelig.ols.comm.unified.frame <- NULL
zelig.ols.comm.divided.frame <- NULL
zelig.efa.comm.unified.frame <- NULL
zelig.efa.comm.divided.frame <- NULL

zelig.ols.median.unified.subs.frame <- NULL
zelig.ols.median.divided.subs.frame <- NULL
zelig.efa.median.unified.subs.frame <- NULL
zelig.efa.median.divided.subs.frame <- NULL

zelig.ols.fil.unified.subs.frame <- NULL
zelig.ols.fil.divided.subs.frame <- NULL
zelig.efa.fil.unified.subs.frame <- NULL
zelig.efa.fil.divided.subs.frame <- NULL

zelig.ols.comm.unified.subs.frame <- NULL
zelig.ols.comm.divided.subs.frame <- NULL
zelig.efa.comm.unified.subs.frame <- NULL
zelig.efa.comm.divided.subs.frame <- NULL

zelig.ols.chair.unified.subs.frame <- NULL
zelig.ols.chair.divided.subs.frame <- NULL
zelig.efa.chair.unified.subs.frame <- NULL
zelig.efa.chair.divided.subs.frame <- NULL

zelig.ols.median.unified.coms.frame <- NULL
zelig.ols.median.divided.coms.frame <- NULL
zelig.efa.median.unified.coms.frame <- NULL
zelig.efa.median.divided.coms.frame <- NULL

zelig.ols.chair.unified.coms.frame <- NULL
zelig.ols.chair.divided.coms.frame <- NULL
zelig.efa.chair.unified.coms.frame <- NULL
zelig.efa.chair.divided.coms.frame <- NULL

zelig.ols.fil.unified.coms.frame <- NULL
zelig.ols.fil.divided.coms.frame <- NULL
zelig.efa.fil.unified.coms.frame <- NULL
zelig.efa.fil.divided.coms.frame <- NULL

zelig.ols.comm.unified.coms.frame <- NULL
zelig.ols.comm.divided.coms.frame <- NULL
zelig.efa.comm.unified.coms.frame <- NULL
zelig.efa.comm.divided.coms.frame <- NULL

zelig.ols.median.unified.neither.frame <- NULL
zelig.ols.median.divided.neither.frame <- NULL
zelig.efa.median.unified.neither.frame <- NULL
zelig.efa.median.divided.neither.frame <- NULL

zelig.ols.fil.unified.neither.frame <- NULL
zelig.ols.fil.divided.neither.frame <- NULL
zelig.efa.fil.unified.neither.frame <- NULL
zelig.efa.fil.divided.neither.frame <- NULL

zelig.ols.chair.unified.neither.frame <- NULL
zelig.ols.chair.divided.neither.frame <- NULL
zelig.efa.chair.unified.neither.frame <- NULL
zelig.efa.chair.divided.neither.frame <- NULL

zelig.ols.comm.unified.neither.frame <- NULL
zelig.ols.comm.divided.neither.frame <- NULL
zelig.efa.comm.unified.neither.frame <- NULL
zelig.efa.comm.divided.neither.frame <- NULL


for(i in 1:100){
  zelig.ols.median.unified.frame <- rbind(zelig.ols.median.unified.frame, 
                                   quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                              zelig.tercile.median.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                            c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.divided.frame <- rbind(zelig.ols.median.divided.frame, 
                                   quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                              zelig.tercile.median.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                            c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.unified.frame <- rbind(zelig.ols.fil.unified.frame, 
                                       quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                  zelig.tercile.fil.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.divided.frame <- rbind(zelig.ols.fil.divided.frame, 
                                       quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                  zelig.tercile.fil.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.unified.frame <- rbind(zelig.ols.comm.unified.frame, 
                                        quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                   zelig.tercile.comm.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.divided.frame <- rbind(zelig.ols.comm.divided.frame, 
                                        quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                   zelig.tercile.comm.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.unified.frame <- rbind(zelig.ols.chair.unified.frame, 
                                         quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                    zelig.tercile.chair.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                  c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.divided.frame <- rbind(zelig.ols.chair.divided.frame, 
                                         quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                    zelig.tercile.chair.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                  c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.efa.median.unified.frame <- rbind(zelig.efa.median.unified.frame, 
                                          quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                     zelig.tercile.median.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                   c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.divided.frame <- rbind(zelig.efa.median.divided.frame, 
                                          quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                     zelig.tercile.median.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                   c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.unified.frame <- rbind(zelig.efa.fil.unified.frame, 
                                       quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                  zelig.tercile.fil.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.divided.frame <- rbind(zelig.efa.fil.divided.frame, 
                                       quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                  zelig.tercile.fil.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.unified.frame <- rbind(zelig.efa.comm.unified.frame, 
                                        quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                   zelig.tercile.comm.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.divided.frame <- rbind(zelig.efa.comm.divided.frame, 
                                        quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                   zelig.tercile.comm.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.unified.frame <- rbind(zelig.efa.chair.unified.frame, 
                                         quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                    zelig.tercile.chair.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                  c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.divided.frame <- rbind(zelig.efa.chair.divided.frame, 
                                         quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1] - 
                                                    zelig.tercile.chair.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                  c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.ols.median.unified.subs.frame <- rbind(zelig.ols.median.unified.subs.frame, 
                                        quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.unified.neither.frame <- rbind(zelig.ols.median.unified.neither.frame, 
                                        quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.unified.coms.frame <- rbind(zelig.ols.median.unified.coms.frame, 
                                           quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                    c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.divided.subs.frame <- rbind(zelig.ols.median.divided.subs.frame, 
                                        quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.divided.neither.frame <- rbind(zelig.ols.median.divided.neither.frame, 
                                           quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                    c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.median.divided.coms.frame <- rbind(zelig.ols.median.divided.coms.frame, 
                                        quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                 c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.ols.fil.unified.subs.frame <- rbind(zelig.ols.fil.unified.subs.frame, 
                                            quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.unified.neither.frame <- rbind(zelig.ols.fil.unified.neither.frame, 
                                               quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.unified.coms.frame <- rbind(zelig.ols.fil.unified.coms.frame, 
                                            quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.divided.subs.frame <- rbind(zelig.ols.fil.divided.subs.frame, 
                                            quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.divided.neither.frame <- rbind(zelig.ols.fil.divided.neither.frame, 
                                               quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.fil.divided.coms.frame <- rbind(zelig.ols.fil.divided.coms.frame, 
                                            quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.ols.comm.unified.subs.frame <- rbind(zelig.ols.comm.unified.subs.frame, 
                                             quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.unified.neither.frame <- rbind(zelig.ols.comm.unified.neither.frame, 
                                                quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                         c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.unified.coms.frame <- rbind(zelig.ols.comm.unified.coms.frame, 
                                             quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.divided.subs.frame <- rbind(zelig.ols.comm.divided.subs.frame, 
                                             quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.divided.neither.frame <- rbind(zelig.ols.comm.divided.neither.frame, 
                                                quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                         c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.comm.divided.coms.frame <- rbind(zelig.ols.comm.divided.coms.frame, 
                                             quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.ols.chair.unified.subs.frame <- rbind(zelig.ols.chair.unified.subs.frame, 
                                              quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.unified.neither.frame <- rbind(zelig.ols.chair.unified.neither.frame, 
                                                 quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                          c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.unified.coms.frame <- rbind(zelig.ols.chair.unified.coms.frame, 
                                              quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.divided.subs.frame <- rbind(zelig.ols.chair.divided.subs.frame, 
                                              quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.divided.neither.frame <- rbind(zelig.ols.chair.divided.neither.frame, 
                                                 quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                          c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.ols.chair.divided.coms.frame <- rbind(zelig.ols.chair.divided.coms.frame, 
                                              quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.efa.median.unified.subs.frame <- rbind(zelig.efa.median.unified.subs.frame, 
                                               quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.unified.neither.frame <- rbind(zelig.efa.median.unified.neither.frame, 
                                                  quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                           c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.unified.coms.frame <- rbind(zelig.efa.median.unified.coms.frame, 
                                               quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.divided.subs.frame <- rbind(zelig.efa.median.divided.subs.frame, 
                                               quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.divided.neither.frame <- rbind(zelig.efa.median.divided.neither.frame, 
                                                  quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                           c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.median.divided.coms.frame <- rbind(zelig.efa.median.divided.coms.frame, 
                                               quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.efa.fil.unified.subs.frame <- rbind(zelig.efa.fil.unified.subs.frame, 
                                            quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.unified.neither.frame <- rbind(zelig.efa.fil.unified.neither.frame, 
                                               quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.unified.coms.frame <- rbind(zelig.efa.fil.unified.coms.frame, 
                                            quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.divided.subs.frame <- rbind(zelig.efa.fil.divided.subs.frame, 
                                            quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.divided.neither.frame <- rbind(zelig.efa.fil.divided.neither.frame, 
                                               quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                        c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.fil.divided.coms.frame <- rbind(zelig.efa.fil.divided.coms.frame, 
                                            quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                     c(0.025,0.05,0.5,0.95,0.975)))
  
  
  zelig.efa.comm.unified.subs.frame <- rbind(zelig.efa.comm.unified.subs.frame, 
                                             quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.unified.neither.frame <- rbind(zelig.efa.comm.unified.neither.frame, 
                                                quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                         c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.unified.coms.frame <- rbind(zelig.efa.comm.unified.coms.frame, 
                                             quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.divided.subs.frame <- rbind(zelig.efa.comm.divided.subs.frame, 
                                             quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.divided.neither.frame <- rbind(zelig.efa.comm.divided.neither.frame, 
                                                quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                         c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.comm.divided.coms.frame <- rbind(zelig.efa.comm.divided.coms.frame, 
                                             quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                      c(0.025,0.05,0.5,0.95,0.975)))
  
  
  
  
  zelig.efa.chair.unified.subs.frame <- rbind(zelig.efa.chair.unified.subs.frame, 
                                              quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.unified.neither.frame <- rbind(zelig.efa.chair.unified.neither.frame, 
                                                 quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                          c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.unified.coms.frame <- rbind(zelig.efa.chair.unified.coms.frame, 
                                              quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.divided.subs.frame <- rbind(zelig.efa.chair.divided.subs.frame, 
                                              quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,1], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.divided.neither.frame <- rbind(zelig.efa.chair.divided.neither.frame, 
                                                 quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,2], 
                                                          c(0.025,0.05,0.5,0.95,0.975)))
  
  zelig.efa.chair.divided.coms.frame <- rbind(zelig.efa.chair.divided.coms.frame, 
                                              quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[i]]$ev[[1]][,3], 
                                                       c(0.025,0.05,0.5,0.95,0.975)))
  
  
  }






zelig.tercile.median.component.frame <- as.data.frame(rbind(data.frame(zelig.ols.median.unified.subs.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Substitutes"),
                                                            data.frame(zelig.ols.median.unified.neither.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Neither"),
                                                            data.frame(zelig.ols.median.unified.coms.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Complements"),
                                                            data.frame(zelig.ols.median.divided.subs.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Substitutes"),
                                                            data.frame(zelig.ols.median.divided.neither.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Neither"),
                                                            data.frame(zelig.ols.median.divided.coms.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Complements"),
                                                            
                                                            data.frame(zelig.efa.median.unified.subs.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Substitutes"),
                                                            data.frame(zelig.efa.median.unified.neither.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Neither"),
                                                            data.frame(zelig.efa.median.unified.coms.frame, 
                                                                       Divided = "Unified Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_unified_med, to = c(0, 100)), 
                                                                       Outcome = "Complements"),
                                                            data.frame(zelig.efa.median.divided.subs.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Substitutes"),
                                                            data.frame(zelig.efa.median.divided.neither.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Neither"),
                                                            data.frame(zelig.efa.median.divided.coms.frame, 
                                                                       Divided = "Divided Government", 
                                                                       Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                       Distance = scales::rescale(seq_alt_divided_med, to = c(0, 100)), 
                                                                       Outcome = "Complements")))



zelig.tercile.fil.component.frame <- as.data.frame(rbind(data.frame(zelig.ols.fil.unified.subs.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Substitutes"),
                                                         data.frame(zelig.ols.fil.unified.neither.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Neither"),
                                                         data.frame(zelig.ols.fil.unified.coms.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Complements"),
                                                         data.frame(zelig.ols.fil.divided.subs.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Substitutes"),
                                                         data.frame(zelig.ols.fil.divided.neither.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Neither"),
                                                         data.frame(zelig.ols.fil.divided.coms.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Complements"),
                                                         
                                                         data.frame(zelig.efa.fil.unified.subs.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Substitutes"),
                                                         data.frame(zelig.efa.fil.unified.neither.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Neither"),
                                                         data.frame(zelig.efa.fil.unified.coms.frame, 
                                                                    Divided = "Unified Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 
                                                                    Outcome = "Complements"),
                                                         data.frame(zelig.efa.fil.divided.subs.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Substitutes"),
                                                         data.frame(zelig.efa.fil.divided.neither.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Neither"),
                                                         data.frame(zelig.efa.fil.divided.coms.frame, 
                                                                    Divided = "Divided Government", 
                                                                    Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                    Distance = scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 
                                                                    Outcome = "Complements")))



zelig.tercile.comm.component.frame <- as.data.frame(rbind(data.frame(zelig.ols.comm.unified.subs.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Substitutes"),
                                                          data.frame(zelig.ols.comm.unified.neither.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Neither"),
                                                          data.frame(zelig.ols.comm.unified.coms.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Complements"),
                                                          data.frame(zelig.ols.comm.divided.subs.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Substitutes"),
                                                          data.frame(zelig.ols.comm.divided.neither.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Neither"),
                                                          data.frame(zelig.ols.comm.divided.coms.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Complements"),
                                                          
                                                          data.frame(zelig.efa.comm.unified.subs.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Substitutes"),
                                                          data.frame(zelig.efa.comm.unified.neither.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Neither"),
                                                          data.frame(zelig.efa.comm.unified.coms.frame, 
                                                                     Divided = "Unified Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_unified_com, to = c(0, 100)), 
                                                                     Outcome = "Complements"),
                                                          data.frame(zelig.efa.comm.divided.subs.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Substitutes"),
                                                          data.frame(zelig.efa.comm.divided.neither.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Neither"),
                                                          data.frame(zelig.efa.comm.divided.coms.frame, 
                                                                     Divided = "Divided Government", 
                                                                     Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                     Distance = scales::rescale(seq_alt_divided_com, to = c(0, 100)), 
                                                                     Outcome = "Complements")))



zelig.tercile.chair.component.frame <- as.data.frame(rbind(data.frame(zelig.ols.chair.unified.subs.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Substitutes"),
                                                           data.frame(zelig.ols.chair.unified.neither.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Neither"),
                                                           data.frame(zelig.ols.chair.unified.coms.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Complements"),
                                                           data.frame(zelig.ols.chair.divided.subs.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Substitutes"),
                                                           data.frame(zelig.ols.chair.divided.neither.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Neither"),
                                                           data.frame(zelig.ols.chair.divided.coms.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Complements"),
                                                           
                                                           data.frame(zelig.efa.chair.unified.subs.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Substitutes"),
                                                           data.frame(zelig.efa.chair.unified.neither.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Neither"),
                                                           data.frame(zelig.efa.chair.unified.coms.frame, 
                                                                      Divided = "Unified Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 
                                                                      Outcome = "Complements"),
                                                           data.frame(zelig.efa.chair.divided.subs.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Substitutes"),
                                                           data.frame(zelig.efa.chair.divided.neither.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Neither"),
                                                           data.frame(zelig.efa.chair.divided.coms.frame, 
                                                                      Divided = "Divided Government", 
                                                                      Estimator = "Exploratory Factor Analysis\n(Two-Factor)", 
                                                                      Distance = scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 
                                                                      Outcome = "Complements")))





zelig.tercile.median.combined.frame <- as.data.frame(rbind(zelig.ols.median.unified.frame,
                                                           zelig.efa.median.unified.frame,
                                                           zelig.ols.median.divided.frame,
                                                           zelig.efa.median.divided.frame))

zelig.tercile.fil.combined.frame <- as.data.frame(rbind(zelig.ols.fil.unified.frame,
                                                        zelig.efa.fil.unified.frame,
                                                        zelig.ols.fil.divided.frame,
                                                        zelig.efa.fil.divided.frame))

zelig.tercile.comm.combined.frame <- as.data.frame(rbind(zelig.ols.comm.unified.frame,
                                                         zelig.efa.comm.unified.frame,
                                                         zelig.ols.comm.divided.frame,
                                                         zelig.efa.comm.divided.frame))

zelig.tercile.chair.combined.frame <- as.data.frame(rbind(zelig.ols.chair.unified.frame,
                                                          zelig.efa.chair.unified.frame,
                                                          zelig.ols.chair.divided.frame,
                                                          zelig.efa.chair.divided.frame))


zelig.tercile.median.combined.frame$Divided <- c(rep("Unified Government", i*2), rep("Divided Government", i*2))
zelig.tercile.median.combined.frame$Divided <- factor(zelig.tercile.median.combined.frame$Divided, 
                                                      levels = c("Unified Government", 
                                                                 "Divided Government"))

zelig.tercile.fil.combined.frame$Divided <- c(rep("Unified Government", i*2), rep("Divided Government", i*2))
zelig.tercile.fil.combined.frame$Divided <- factor(zelig.tercile.fil.combined.frame$Divided, 
                                                      levels = c("Unified Government", 
                                                                 "Divided Government"))

zelig.tercile.comm.combined.frame$Divided <- c(rep("Unified Government", i*2), rep("Divided Government", i*2))
zelig.tercile.comm.combined.frame$Divided <- factor(zelig.tercile.comm.combined.frame$Divided, 
                                                   levels = c("Unified Government", 
                                                              "Divided Government"))

zelig.tercile.chair.combined.frame$Divided <- c(rep("Unified Government", i*2), rep("Divided Government", i*2))
zelig.tercile.chair.combined.frame$Divided <- factor(zelig.tercile.chair.combined.frame$Divided, 
                                                    levels = c("Unified Government", 
                                                               "Divided Government"))



zelig.tercile.median.combined.frame$Estimator <- c(rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                            rep("Exploratory Factor Analysis\n(Two-Factor)", i),
                                            rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                            rep("Exploratory Factor Analysis\n(Two-Factor)", i))

zelig.tercile.fil.combined.frame$Estimator <- c(rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                            rep("Exploratory Factor Analysis\n(Two-Factor)", i),
                                            rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                            rep("Exploratory Factor Analysis\n(Two-Factor)", i))

zelig.tercile.chair.combined.frame$Estimator <- c(rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                                rep("Exploratory Factor Analysis\n(Two-Factor)", i),
                                                rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                                rep("Exploratory Factor Analysis\n(Two-Factor)", i))


zelig.tercile.comm.combined.frame$Estimator <- c(rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                                  rep("Exploratory Factor Analysis\n(Two-Factor)", i),
                                                  rep("Regression-Based\n(Original Krause & O'Connell Scores)", i), 
                                                  rep("Exploratory Factor Analysis\n(Two-Factor)", i))



zelig.tercile.median.combined.frame$Estimator <- factor(zelig.tercile.median.combined.frame$Estimator, 
                                             levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                        "Exploratory Factor Analysis\n(Two-Factor)"))


zelig.tercile.fil.combined.frame$Estimator <- factor(zelig.tercile.fil.combined.frame$Estimator, 
                                                        levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                   "Exploratory Factor Analysis\n(Two-Factor)"))

zelig.tercile.chair.combined.frame$Estimator <- factor(zelig.tercile.chair.combined.frame$Estimator, 
                                                     levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                "Exploratory Factor Analysis\n(Two-Factor)"))

zelig.tercile.comm.combined.frame$Estimator <- factor(zelig.tercile.comm.combined.frame$Estimator, 
                                                       levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                  "Exploratory Factor Analysis\n(Two-Factor)"))



zelig.tercile.median.combined.frame$Distance <- c(rep(scales::rescale(seq_alt_unified_med, to = c(0, 100)), 2),
                                                  rep(scales::rescale(seq_alt_divided_med, to = c(0, 100)), 2))

zelig.tercile.fil.combined.frame$Distance <- c(rep(scales::rescale(seq_alt_unified_fil, to = c(0, 100)), 2),
                                               rep(scales::rescale(seq_alt_divided_fil, to = c(0, 100)), 2))

zelig.tercile.comm.combined.frame$Distance <- c(rep(scales::rescale(seq_alt_unified_com, to = c(0, 100)), 2),
                                                rep(scales::rescale(seq_alt_divided_com, to = c(0, 100)), 2))

zelig.tercile.chair.combined.frame$Distance <- c(rep(scales::rescale(seq_alt_unified_cha, to = c(0, 100)), 2),
                                                 rep(scales::rescale(seq_alt_divided_cha, to = c(0, 100)), 2))



colnames(zelig.tercile.median.combined.frame)[1:5] <- c("low95", "low90", "pred", "high90", "high95")
colnames(zelig.tercile.fil.combined.frame)[1:5] <- c("low95", "low90", "pred", "high90", "high95")
colnames(zelig.tercile.comm.combined.frame)[1:5] <- c("low95", "low90", "pred", "high90", "high95")
colnames(zelig.tercile.chair.combined.frame)[1:5] <- c("low95", "low90", "pred", "high90", "high95")

# 
# ologit.tercile.median.mean.plot <- ggplot(subset(zelig.tercile.median.combined.frame, 
#                                           Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
#                                                            "Exploratory Factor Analysis\n(Two-Factor)")),
#                                    aes(x = Distance, y = pred)) + 
#                               geom_hline(yintercept = 0, linetype = "dotted") + 
#                               geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#                               geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#                               geom_line() + 
#                               theme_bw() + 
#                               xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#                               ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#                               facet_grid(Divided ~ Estimator) + 
#                               ylim(-1, 1)
# 
# ologit.tercile.fil.mean.plot <- ggplot(subset(zelig.tercile.fil.combined.frame, 
#                                                  Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
#                                                                   "Exploratory Factor Analysis\n(Two-Factor)")),
#                                           aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# ologit.tercile.chair.mean.plot <- ggplot(subset(zelig.tercile.chair.combined.frame, 
#                                               Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
#                                                                "Exploratory Factor Analysis\n(Two-Factor)")),
#                                        aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# ologit.tercile.comm.mean.plot <- ggplot(subset(zelig.tercile.comm.combined.frame, 
#                                                 Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
#                                                                  "Exploratory Factor Analysis\n(Two-Factor)")),
#                                          aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Median Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# 
# ologit.tercile.median.mean.plot.full <- ggplot(zelig.tercile.median.combined.frame,
#                                    aes(x = Distance, y = pred)) + 
#                                  geom_hline(yintercept = 0, linetype = "dotted") + 
#                                  geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#                                  geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#                                  geom_line() + 
#                                  theme_bw() + 
#                                  xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#                                  ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#                                  facet_grid(Divided ~ Estimator) + 
#                                  ylim(-1, 1)
# 
# ologit.tercile.fil.mean.plot.full <- ggplot(zelig.tercile.fil.combined.frame,
#                                                aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# ologit.tercile.chair.mean.plot.full <- ggplot(zelig.tercile.chair.combined.frame,
#                                                aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# ologit.tercile.comm.mean.plot.full <- ggplot(zelig.tercile.comm.combined.frame,
#                                                aes(x = Distance, y = pred)) + 
#   geom_hline(yintercept = 0, linetype = "dotted") + 
#   geom_ribbon(aes(ymin = low95, ymax = high95), color = NA, alpha = 0.25) + 
#   geom_ribbon(aes(ymin = low90, ymax = high90), color = NA, alpha = 0.65) + 
#   geom_line() + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Substitutes Minus Probability of Complements\n') + 
#   facet_grid(Divided ~ Estimator) + 
#   ylim(-1, 1)
# 
# 
# 
# 
# 
# 
# tercile.ols.median.allprobs.plot <- ggplot(subset(zelig.tercile.median.component.frame, 
#                                            Estimator == "Regression-Based\n(Original Krause & O'Connell Scores)"), 
#                                    aes(x = Distance, y = X50.)) + 
#                               geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#                               geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#                               geom_line() + 
#                               facet_grid(Divided ~ Outcome) + 
#                               theme_bw() + 
#                               xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#                               ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# tercile.ols.fil.allprobs.plot <- ggplot(subset(zelig.tercile.fil.component.frame, 
#                                                   Estimator == "Regression-Based\n(Original Krause & O'Connell Scores)"), 
#                                            aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
#   
# 
# 
# tercile.ols.comm.allprobs.plot <- ggplot(subset(zelig.tercile.comm.component.frame, 
#                                                Estimator == "Regression-Based\n(Original Krause & O'Connell Scores)"), 
#                                         aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# 
# tercile.ols.chair.allprobs.plot <- ggplot(subset(zelig.tercile.chair.component.frame, 
#                                                 Estimator == "Regression-Based\n(Original Krause & O'Connell Scores)"), 
#                                          aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# tercile.efa.median.allprobs.plot <- ggplot(subset(zelig.tercile.median.component.frame, Estimator == "Exploratory Factor Analysis\n(Two-Factor)"), 
#                                    aes(x = Distance, y = X50.)) + 
#                               geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#                               geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#                               geom_line() + 
#                               facet_grid(Divided ~ Outcome) + 
#                               theme_bw() + 
#                               xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#                               ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# tercile.efa.fil.allprobs.plot <- ggplot(subset(zelig.tercile.fil.component.frame, Estimator == "Exploratory Factor Analysis\n(Two-Factor)"), 
#                                            aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# 
# tercile.efa.chair.allprobs.plot <- ggplot(subset(zelig.tercile.chair.component.frame, Estimator == "Exploratory Factor Analysis\n(Two-Factor)"), 
#                                         aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# 
# tercile.efa.comm.allprobs.plot <- ggplot(subset(zelig.tercile.comm.component.frame, Estimator == "Exploratory Factor Analysis\n(Two-Factor)"), 
#                                           aes(x = Distance, y = X50.)) + 
#   geom_ribbon(aes(ymin = X5., ymax = X95.), alpha = 0.5, color = NA) + 
#   geom_ribbon(aes(ymin = X2.5., ymax = X97.5.), alpha = 0.3, color = NA) + 
#   geom_line() + 
#   facet_grid(Divided ~ Outcome) + 
#   theme_bw() + 
#   xlab('\nAbsolute President-Committee Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
#   ylab('Probability of Indicated Outcome\n') + ylim(0, 1)
# 
# 
# 
# 
# ggsave(ologit.tercile.median.mean.plot, file = "Ologit-Tercile-Median-Mean-Plot-Policy.png", height = 6, width = 8)
# ggsave(ologit.tercile.median.mean.plot, file = "Ologit-Tercile-Median-Mean-Plot-Policy.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.fil.mean.plot, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy.png", height = 6, width = 8)
# ggsave(ologit.tercile.fil.mean.plot, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.comm.mean.plot, file = "Ologit-Tercile-Committee-Mean-Plot-Policy.png", height = 6, width = 8)
# ggsave(ologit.tercile.comm.mean.plot, file = "Ologit-Tercile-Committee-Mean-Plot-Policy.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.chair.mean.plot, file = "Ologit-Tercile-Chair-Mean-Plot-Policy.png", height = 6, width = 8)
# ggsave(ologit.tercile.chair.mean.plot, file = "Ologit-Tercile-Chair-Mean-Plot-Policy.pdf", height = 6, width = 8)
# 
# ggsave(ologit.tercile.median.mean.plot, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.median.mean.plot, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.fil.mean.plot, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.fil.mean.plot, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.comm.mean.plot, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.comm.mean.plot, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.chair.mean.plot, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.chair.mean.plot, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Pres.pdf", height = 6*(.725), width = 10*(.725))
# 
# ggsave(ologit.tercile.median.mean.plot.full, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Full.png", height = 6, width = 8)
# ggsave(ologit.tercile.median.mean.plot.full, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Full.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.fil.mean.plot.full, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Full.png", height = 6, width = 8)
# ggsave(ologit.tercile.fil.mean.plot.full, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Full.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.comm.mean.plot.full, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Full.png", height = 6, width = 8)
# ggsave(ologit.tercile.comm.mean.plot.full, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Full.pdf", height = 6, width = 8)
# ggsave(ologit.tercile.chair.mean.plot.full, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Full.png", height = 6, width = 8)
# ggsave(ologit.tercile.chair.mean.plot.full, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Full.pdf", height = 6, width = 8)
# 
# ggsave(ologit.tercile.median.mean.plot.full, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Full-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.median.mean.plot.full, file = "Ologit-Tercile-Median-Mean-Plot-Policy-Full-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.fil.mean.plot.full, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Full-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.fil.mean.plot.full, file = "Ologit-Tercile-Filibuster-Mean-Plot-Policy-Full-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.comm.mean.plot.full, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Full-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.comm.mean.plot.full, file = "Ologit-Tercile-Committee-Mean-Plot-Policy-Full-Pres.pdf", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.chair.mean.plot.full, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Full-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(ologit.tercile.chair.mean.plot.full, file = "Ologit-Tercile-Chair-Mean-Plot-Policy-Full-Pres.pdf", height = 6*(.725), width = 10*(.725))
# 
# 
# 
# 
# ggsave(tercile.ols.median.allprobs.plot, file = "Ologit-Tercile-OLS-Median-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.ols.fil.allprobs.plot, file = "Ologit-Tercile-OLS-Filibuster-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.ols.comm.allprobs.plot, file = "Ologit-Tercile-OLS-Committee-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.ols.chair.allprobs.plot, file = "Ologit-Tercile-OLS-Chair-AllProbs-Plot-Policy.png", height = 4, width = 6)
# 
# ggsave(tercile.efa.median.allprobs.plot, file = "Ologit-Tercile-EFA-Median-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.efa.fil.allprobs.plot, file = "Ologit-Tercile-EFA-Filibuster-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.efa.comm.allprobs.plot, file = "Ologit-Tercile-EFA-Committee-AllProbs-Plot-Policy.png", height = 4, width = 6)
# ggsave(tercile.efa.chair.allprobs.plot, file = "Ologit-Tercile-EFA-Chair-AllProbs-Plot-Policy.png", height = 4, width = 6)
# 
# ggsave(tercile.ols.median.allprobs.plot, file = "Ologit-Tercile-OLS-Median-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.ols.fil.allprobs.plot, file = "Ologit-Tercile-OLS-Filibuster-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.ols.comm.allprobs.plot, file = "Ologit-Tercile-OLS-Committee-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.ols.chair.allprobs.plot, file = "Ologit-Tercile-OLS-Chair-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.efa.median.allprobs.plot, file = "Ologit-Tercile-EFA-Median-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.efa.fil.allprobs.plot, file = "Ologit-Tercile-EFA-Filibuster-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.efa.comm.allprobs.plot, file = "Ologit-Tercile-EFA-Committee-AllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# ggsave(tercile.efa.chair.allprobs.plot, file = "Ologit-Tercile-EFA-ChairAllProbs-Plot-Policy-Pres.png", height = 6*(.725), width = 10*(.725))
# 
# 
# 








# "marginal effects" plots
tercile.ols.median.unified.mfx <- quantile((zelig.tercile.median.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.median.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.median.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.median.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.median.divided.mfx <- quantile((zelig.tercile.median.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.median.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.median.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.median.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.fil.unified.mfx <- quantile((zelig.tercile.fil.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.fil.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.fil.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.fil.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.fil.divided.mfx <- quantile((zelig.tercile.fil.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.fil.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.fil.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.fil.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.comm.unified.mfx <- quantile((zelig.tercile.comm.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                           zelig.tercile.comm.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                          (zelig.tercile.comm.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                             zelig.tercile.comm.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                        c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.comm.divided.mfx <- quantile((zelig.tercile.comm.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                           zelig.tercile.comm.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                          (zelig.tercile.comm.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                             zelig.tercile.comm.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                        c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.chair.unified.mfx <- quantile((zelig.tercile.chair.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                            zelig.tercile.chair.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                           (zelig.tercile.chair.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                              zelig.tercile.chair.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                         c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.ols.chair.divided.mfx <- quantile((zelig.tercile.chair.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                            zelig.tercile.chair.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                           (zelig.tercile.chair.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                              zelig.tercile.chair.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                         c(0.025, 0.05, 0.5, 0.95, 0.975))


tercile.efa.median.unified.mfx <- quantile((zelig.tercile.median.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.median.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.median.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.median.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.median.divided.mfx <- quantile((zelig.tercile.median.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                              zelig.tercile.median.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                             (zelig.tercile.median.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                                zelig.tercile.median.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                           c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.fil.unified.mfx <- quantile((zelig.tercile.fil.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                           zelig.tercile.fil.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                          (zelig.tercile.fil.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                             zelig.tercile.fil.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                        c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.fil.divided.mfx <- quantile((zelig.tercile.fil.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                           zelig.tercile.fil.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                          (zelig.tercile.fil.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                             zelig.tercile.fil.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                        c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.comm.unified.mfx <- quantile((zelig.tercile.comm.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                            zelig.tercile.comm.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                           (zelig.tercile.comm.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                              zelig.tercile.comm.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                         c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.comm.divided.mfx <- quantile((zelig.tercile.comm.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                            zelig.tercile.comm.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                           (zelig.tercile.comm.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                              zelig.tercile.comm.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                         c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.chair.unified.mfx <- quantile((zelig.tercile.chair.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                             zelig.tercile.chair.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                            (zelig.tercile.chair.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                               zelig.tercile.chair.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                          c(0.025, 0.05, 0.5, 0.95, 0.975))

tercile.efa.chair.divided.mfx <- quantile((zelig.tercile.chair.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] - 
                                             zelig.tercile.chair.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3]) - 
                                            (zelig.tercile.chair.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1] - 
                                               zelig.tercile.chair.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3]), 
                                          c(0.025, 0.05, 0.5, 0.95, 0.975))


tercile.mfx <- data.frame(rbind(tercile.ols.median.unified.mfx,
                                tercile.ols.median.divided.mfx,
                                tercile.ols.fil.unified.mfx,
                                tercile.ols.fil.divided.mfx,
                                tercile.ols.comm.unified.mfx,
                                tercile.ols.comm.divided.mfx,
                                tercile.ols.chair.unified.mfx,
                                tercile.ols.chair.divided.mfx,
                                tercile.efa.median.unified.mfx,
                                tercile.efa.median.divided.mfx,
                                tercile.efa.fil.unified.mfx,
                                tercile.efa.fil.divided.mfx,
                                tercile.efa.comm.unified.mfx,
                                tercile.efa.comm.divided.mfx,
                                tercile.efa.chair.unified.mfx,
                                tercile.efa.chair.divided.mfx))

rownames(tercile.mfx) <- 1:length(rownames(tercile.mfx))        

tercile.mfx$Divided <- rep(c("Unified Government", "Divided Government"), 8)

tercile.mfx$Divided <- factor(tercile.mfx$Divided, levels = c("Unified Government", "Divided Government"))

tercile.mfx$Pivot <- rep(c("Senate Median", "Senate Median", 
                           "Filibuster Pivot", "Filibuster Pivot",
                           "Committee Median", "Committee Median",
                           "Committee Chair", "Committee Chair"), 2)

tercile.mfx$Pivot <- factor(tercile.mfx$Pivot, levels = c("Senate Median", "Filibuster Pivot",
                                                          "Committee Chair", "Committee Median"))

tercile.mfx$Estimator <- c(rep("Regression-Based", 8),
                         rep("Exploratory Factor Analysis", 8))

tercile.mfx$Estimator <- factor(tercile.mfx$Estimator,
                              levels = c("Regression-Based", "Exploratory Factor Analysis"))


tercile.mfx.plot.full <- ggplot(tercile.mfx, 
                           aes(x = Pivot, y = X50., ymin = X5., ymax = X95., color = Estimator, shape = Estimator)) + 
  geom_hline(yintercept = 0, linetype = "dashed") + 
  geom_errorbar(position = position_dodge(width = 0.4), width = 0.3) + 
  geom_errorbar(aes(ymin = X2.5., ymax = X97.5.), width = 0, position = position_dodge(width = 0.4)) + 
  facet_wrap(~ Divided) + 
  geom_point(position = position_dodge(width = 0.4), size = 2) + 
  theme_bw() + 
  theme(legend.position="bottom", legend.box="vertical", legend.margin=margin(), 
        axis.text.x = element_text(angle = 45, vjust =1 , hjust=1)) + 
  scale_colour_grey(start = 0, end = 0.8) + 
  xlab('\nPivot of Interest') + 
  ylab('Change in Difference in Probability\nof Substitutes Versus Probability of Complements\n')


ggsave(tercile.mfx.plot.full, file = "Figure-4.png", height = 6, width = 10)
ggsave(tercile.mfx.plot.full, file = "Figure-4.pdf", height = 6, width = 10)






### outcome probabilities (as mfx)
mfx.subs.tercile.median.ols.divided <- data.frame(t(quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                             zelig.tercile.median.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Substitutes",
                                                  Government = "Divided Government")

mfx.subs.tercile.median.ols.unified <- data.frame(t(quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                               zelig.tercile.median.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Substitutes",
                                                  Government = "Unified Government")

mfx.neither.tercile.median.ols.divided <- data.frame(t(quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.median.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Neither",
                                                  Government = "Divided Government")

mfx.neither.tercile.median.ols.unified <- data.frame(t(quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.median.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Neither",
                                                  Government = "Unified Government")


mfx.comps.tercile.median.ols.divided <- data.frame(t(quantile(zelig.tercile.median.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                                  zelig.tercile.median.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                                c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                     Pivot = "Senate Median",
                                                     Estimator = "Regression-Based",
                                                     Outcome = "Complements",
                                                     Government = "Divided Government")

mfx.comps.tercile.median.ols.unified <- data.frame(t(quantile(zelig.tercile.median.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                                  zelig.tercile.median.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                                c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                     Pivot = "Senate Median",
                                                     Estimator = "Regression-Based",
                                                     Outcome = "Complements",
                                                     Government = "Unified Government")


mfx.subs.tercile.median.efa.divided <- data.frame(t(quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                               zelig.tercile.median.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Substitutes",
                                                  Government = "Divided Government")

mfx.subs.tercile.median.efa.unified <- data.frame(t(quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                               zelig.tercile.median.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Senate Median",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Substitutes",
                                                  Government = "Unified Government")

mfx.neither.tercile.median.efa.divided <- data.frame(t(quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                  zelig.tercile.median.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                                c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                     Pivot = "Senate Median",
                                                     Estimator = "Exploratory Factor Analysis",
                                                     Outcome = "Neither",
                                                     Government = "Divided Government")

mfx.neither.tercile.median.efa.unified <- data.frame(t(quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                  zelig.tercile.median.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                                c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                     Pivot = "Senate Median",
                                                     Estimator = "Exploratory Factor Analysis",
                                                     Outcome = "Neither",
                                                     Government = "Unified Government")


mfx.comps.tercile.median.efa.divided <- data.frame(t(quantile(zelig.tercile.median.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                                zelig.tercile.median.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Senate Median",
                                                   Estimator = "Exploratory Factor Analysis",
                                                   Outcome = "Complements",
                                                   Government = "Divided Government")

mfx.comps.tercile.median.efa.unified <- data.frame(t(quantile(zelig.tercile.median.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                                zelig.tercile.median.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Senate Median",
                                                   Estimator = "Exploratory Factor Analysis",
                                                   Outcome = "Complements",
                                                   Government = "Unified Government")

mfx.subs.tercile.fil.ols.divided <- data.frame(t(quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                            zelig.tercile.fil.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                          c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                               Pivot = "Filibuster Pivot",
                                               Estimator = "Regression-Based",
                                               Outcome = "Substitutes",
                                               Government = "Divided Government")

mfx.subs.tercile.fil.ols.unified <- data.frame(t(quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                            zelig.tercile.fil.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                          c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                               Pivot = "Filibuster Pivot",
                                               Estimator = "Regression-Based",
                                               Outcome = "Substitutes",
                                               Government = "Unified Government")

mfx.neither.tercile.fil.ols.divided <- data.frame(t(quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.fil.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Filibuster Pivot",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Neither",
                                                  Government = "Divided Government")

mfx.neither.tercile.fil.ols.unified <- data.frame(t(quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.fil.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Filibuster Pivot",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Neither",
                                                  Government = "Unified Government")


mfx.comps.tercile.fil.ols.divided <- data.frame(t(quantile(zelig.tercile.fil.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                             zelig.tercile.fil.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Filibuster Pivot",
                                                Estimator = "Regression-Based",
                                                Outcome = "Complements",
                                                Government = "Divided Government")

mfx.comps.tercile.fil.ols.unified <- data.frame(t(quantile(zelig.tercile.fil.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                             zelig.tercile.fil.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Filibuster Pivot",
                                                Estimator = "Regression-Based",
                                                Outcome = "Complements",
                                                Government = "Unified Government")


mfx.subs.tercile.fil.efa.divided <- data.frame(t(quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                            zelig.tercile.fil.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                          c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                               Pivot = "Filibuster Pivot",
                                               Estimator = "Exploratory Factor Analysis",
                                               Outcome = "Substitutes",
                                               Government = "Divided Government")

mfx.subs.tercile.fil.efa.unified <- data.frame(t(quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                            zelig.tercile.fil.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                          c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                               Pivot = "Filibuster Pivot",
                                               Estimator = "Exploratory Factor Analysis",
                                               Outcome = "Substitutes",
                                               Government = "Unified Government")

mfx.neither.tercile.fil.efa.divided <- data.frame(t(quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.fil.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Filibuster Pivot",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Neither",
                                                  Government = "Divided Government")

mfx.neither.tercile.fil.efa.unified <- data.frame(t(quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                               zelig.tercile.fil.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Filibuster Pivot",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Neither",
                                                  Government = "Unified Government")


mfx.comps.tercile.fil.efa.divided <- data.frame(t(quantile(zelig.tercile.fil.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                             zelig.tercile.fil.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Filibuster Pivot",
                                                Estimator = "Exploratory Factor Analysis",
                                                Outcome = "Complements",
                                                Government = "Divided Government")

mfx.comps.tercile.fil.efa.unified <- data.frame(t(quantile(zelig.tercile.fil.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                             zelig.tercile.fil.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Filibuster Pivot",
                                                Estimator = "Exploratory Factor Analysis",
                                                Outcome = "Complements",
                                                Government = "Unified Government")

mfx.subs.tercile.comm.ols.divided <- data.frame(t(quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                             zelig.tercile.comm.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Committee Median",
                                                Estimator = "Regression-Based",
                                                Outcome = "Substitutes",
                                                Government = "Divided Government")

mfx.subs.tercile.comm.ols.unified <- data.frame(t(quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                             zelig.tercile.comm.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Committee Median",
                                                Estimator = "Regression-Based",
                                                Outcome = "Substitutes",
                                                Government = "Unified Government")

mfx.neither.tercile.comm.ols.divided <- data.frame(t(quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                zelig.tercile.comm.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Committee Median",
                                                   Estimator = "Regression-Based",
                                                   Outcome = "Neither",
                                                   Government = "Divided Government")

mfx.neither.tercile.comm.ols.unified <- data.frame(t(quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                zelig.tercile.comm.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Committee Median",
                                                   Estimator = "Regression-Based",
                                                   Outcome = "Neither",
                                                   Government = "Unified Government")


mfx.comps.tercile.comm.ols.divided <- data.frame(t(quantile(zelig.tercile.comm.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                              zelig.tercile.comm.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Median",
                                                 Estimator = "Regression-Based",
                                                 Outcome = "Complements",
                                                 Government = "Divided Government")

mfx.comps.tercile.comm.ols.unified <- data.frame(t(quantile(zelig.tercile.comm.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                              zelig.tercile.comm.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Median",
                                                 Estimator = "Regression-Based",
                                                 Outcome = "Complements",
                                                 Government = "Unified Government")


mfx.subs.tercile.comm.efa.divided <- data.frame(t(quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                             zelig.tercile.comm.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Committee Median",
                                                Estimator = "Exploratory Factor Analysis",
                                                Outcome = "Substitutes",
                                                Government = "Divided Government")

mfx.subs.tercile.comm.efa.unified <- data.frame(t(quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                             zelig.tercile.comm.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                           c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                Pivot = "Committee Median",
                                                Estimator = "Exploratory Factor Analysis",
                                                Outcome = "Substitutes",
                                                Government = "Unified Government")

mfx.neither.tercile.comm.efa.divided <- data.frame(t(quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                zelig.tercile.comm.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Committee Median",
                                                   Estimator = "Exploratory Factor Analysis",
                                                   Outcome = "Neither",
                                                   Government = "Divided Government")

mfx.neither.tercile.comm.efa.unified <- data.frame(t(quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                zelig.tercile.comm.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                              c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                   Pivot = "Committee Median",
                                                   Estimator = "Exploratory Factor Analysis",
                                                   Outcome = "Neither",
                                                   Government = "Unified Government")


mfx.comps.tercile.comm.efa.divided <- data.frame(t(quantile(zelig.tercile.comm.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                              zelig.tercile.comm.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Median",
                                                 Estimator = "Exploratory Factor Analysis",
                                                 Outcome = "Complements",
                                                 Government = "Divided Government")

mfx.comps.tercile.comm.efa.unified <- data.frame(t(quantile(zelig.tercile.comm.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                              zelig.tercile.comm.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Median",
                                                 Estimator = "Exploratory Factor Analysis",
                                                 Outcome = "Complements",
                                                 Government = "Unified Government")

mfx.subs.tercile.chair.ols.divided <- data.frame(t(quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                              zelig.tercile.chair.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Chair",
                                                 Estimator = "Regression-Based",
                                                 Outcome = "Substitutes",
                                                 Government = "Divided Government")

mfx.subs.tercile.chair.ols.unified <- data.frame(t(quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                              zelig.tercile.chair.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Chair",
                                                 Estimator = "Regression-Based",
                                                 Outcome = "Substitutes",
                                                 Government = "Unified Government")

mfx.neither.tercile.chair.ols.divided <- data.frame(t(quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                 zelig.tercile.chair.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                               c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                    Pivot = "Committee Chair",
                                                    Estimator = "Regression-Based",
                                                    Outcome = "Neither",
                                                    Government = "Divided Government")

mfx.neither.tercile.chair.ols.unified <- data.frame(t(quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                 zelig.tercile.chair.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                               c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                    Pivot = "Committee Chair",
                                                    Estimator = "Regression-Based",
                                                    Outcome = "Neither",
                                                    Government = "Unified Government")


mfx.comps.tercile.chair.ols.divided <- data.frame(t(quantile(zelig.tercile.chair.ols.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                               zelig.tercile.chair.ols.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Committee Chair",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Complements",
                                                  Government = "Divided Government")

mfx.comps.tercile.chair.ols.unified <- data.frame(t(quantile(zelig.tercile.chair.ols.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                               zelig.tercile.chair.ols.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Committee Chair",
                                                  Estimator = "Regression-Based",
                                                  Outcome = "Complements",
                                                  Government = "Unified Government")


mfx.subs.tercile.chair.efa.divided <- data.frame(t(quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                              zelig.tercile.chair.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Chair",
                                                 Estimator = "Exploratory Factor Analysis",
                                                 Outcome = "Substitutes",
                                                 Government = "Divided Government")

mfx.subs.tercile.chair.efa.unified <- data.frame(t(quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,1] -  
                                                              zelig.tercile.chair.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,1], 
                                                            c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                 Pivot = "Committee Chair",
                                                 Estimator = "Exploratory Factor Analysis",
                                                 Outcome = "Substitutes",
                                                 Government = "Unified Government")

mfx.neither.tercile.chair.efa.divided <- data.frame(t(quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                 zelig.tercile.chair.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                               c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                    Pivot = "Committee Chair",
                                                    Estimator = "Exploratory Factor Analysis",
                                                    Outcome = "Neither",
                                                    Government = "Divided Government")

mfx.neither.tercile.chair.efa.unified <- data.frame(t(quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,2] -  
                                                                 zelig.tercile.chair.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,2], 
                                                               c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                    Pivot = "Committee Chair",
                                                    Estimator = "Exploratory Factor Analysis",
                                                    Outcome = "Neither",
                                                    Government = "Unified Government")


mfx.comps.tercile.chair.efa.divided <- data.frame(t(quantile(zelig.tercile.chair.efa.divided.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                               zelig.tercile.chair.efa.divided.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Committee Chair",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Complements",
                                                  Government = "Divided Government")

mfx.comps.tercile.chair.efa.unified <- data.frame(t(quantile(zelig.tercile.chair.efa.unified.sims$sim.out$range[[75]]$ev[[1]][,3] -  
                                                               zelig.tercile.chair.efa.unified.sims$sim.out$range[[25]]$ev[[1]][,3], 
                                                             c(0.025, 0.05, 0.5, 0.95, 0.975))),
                                                  Pivot = "Committee Chair",
                                                  Estimator = "Exploratory Factor Analysis",
                                                  Outcome = "Complements",
                                                  Government = "Unified Government")



mfx.outcomes.tercile.full <- rbind(mfx.subs.tercile.median.ols.unified,
                                   mfx.subs.tercile.median.ols.divided,
                                   mfx.subs.tercile.fil.ols.unified,
                                   mfx.subs.tercile.fil.ols.divided,
                                   mfx.subs.tercile.chair.ols.unified,
                                   mfx.subs.tercile.chair.ols.divided,
                                   mfx.subs.tercile.comm.ols.unified,
                                   mfx.subs.tercile.comm.ols.divided,
                                   mfx.subs.tercile.median.efa.unified,
                                   mfx.subs.tercile.median.efa.divided,
                                   mfx.subs.tercile.fil.efa.unified,
                                   mfx.subs.tercile.fil.efa.divided,
                                   mfx.subs.tercile.chair.efa.unified,
                                   mfx.subs.tercile.chair.efa.divided,
                                   mfx.subs.tercile.comm.efa.unified,
                                   mfx.subs.tercile.comm.efa.divided,
                                   mfx.neither.tercile.median.ols.unified,
                                   mfx.neither.tercile.median.ols.divided,
                                   mfx.neither.tercile.fil.ols.unified,
                                   mfx.neither.tercile.fil.ols.divided,
                                   mfx.neither.tercile.chair.ols.unified,
                                   mfx.neither.tercile.chair.ols.divided,
                                   mfx.neither.tercile.comm.ols.unified,
                                   mfx.neither.tercile.comm.ols.divided,
                                   mfx.neither.tercile.median.efa.unified,
                                   mfx.neither.tercile.median.efa.divided,
                                   mfx.neither.tercile.fil.efa.unified,
                                   mfx.neither.tercile.fil.efa.divided,
                                   mfx.neither.tercile.chair.efa.unified,
                                   mfx.neither.tercile.chair.efa.divided,
                                   mfx.neither.tercile.comm.efa.unified,
                                   mfx.neither.tercile.comm.efa.divided,
                                   mfx.comps.tercile.median.ols.unified,
                                   mfx.comps.tercile.median.ols.divided,
                                   mfx.comps.tercile.fil.ols.unified,
                                   mfx.comps.tercile.fil.ols.divided,
                                   mfx.comps.tercile.chair.ols.unified,
                                   mfx.comps.tercile.chair.ols.divided,
                                   mfx.comps.tercile.comm.ols.unified,
                                   mfx.comps.tercile.comm.ols.divided,
                                   mfx.comps.tercile.median.efa.unified,
                                   mfx.comps.tercile.median.efa.divided,
                                   mfx.comps.tercile.fil.efa.unified,
                                   mfx.comps.tercile.fil.efa.divided,
                                   mfx.comps.tercile.chair.efa.unified,
                                   mfx.comps.tercile.chair.efa.divided,
                                   mfx.comps.tercile.comm.efa.unified,
                                   mfx.comps.tercile.comm.efa.divided)

mfx.outcomes.tercile.full$Pivot <- factor(mfx.outcomes.tercile.full$Pivot, levels = c("Senate Median",
                                                                                      "Filibuster Pivot",
                                                                                      "Committee Chair",
                                                                                      "Committee Median"))

mfx.outcomes.tercile.full$Outcome <- factor(mfx.outcomes.tercile.full$Outcome, levels = c("Substitutes",
                                                                                          "Neither",
                                                                                          "Complements"))
  
mfx.outcomes.tercile.full$Government <- factor(mfx.outcomes.tercile.full$Government, levels = c("Unified Government",
                                                                                                "Divided Government"))

mfx.outcomes.tercile.full$Estimator <- factor(mfx.outcomes.tercile.full$Estimator, levels = c("Regression-Based",
                                                                                              "Exploratory Factor Analysis"))


mfx.outcomes.tercile.plot.full <- ggplot(subset(mfx.outcomes.tercile.full), 
                                    aes(x = Pivot, y = X50., color = Estimator, shape = Estimator)) + 
  geom_hline(yintercept = 0, linetype = "dashed") + 
  geom_errorbar(aes(ymin = X2.5., ymax = X97.5.),  
                position = position_dodge(width = 0.4), width = 0) + 
  geom_errorbar(aes(ymin = X5., ymax = X95.),  
                position = position_dodge(width = 0.4), width = 0.3) + 
  facet_grid(Outcome ~ Government) + 
  geom_point(position = position_dodge(width = 0.4), size = 2) + 
  theme_bw() + 
  theme(legend.position="bottom", legend.box="vertical", legend.margin=margin(), 
        axis.text.x = element_text(angle = 45, vjust =1 , hjust=1)) + 
  scale_colour_grey(start = 0, end = 0.8,
                    labels = c("Regression-Based", "Exploratory Factor Analysis",
                               "Confirmatory Factor Analysis", 
                               "Generalized Latent Trait Analysis")) + 
  scale_shape_discrete(labels = c("Regression-Based", "Exploratory Factor Analysis",
                                  "Confirmatory Factor Analysis", 
                                  "Generalized Latent Trait Analysis")) + 
  xlab('\nPivot of Interest') + 
  ylab('Change in Probability of Indicated Outcomes\n')

ggsave(mfx.outcomes.tercile.plot.full, file = "Figure-3.png", height = 6, width = 10)
ggsave(mfx.outcomes.tercile.plot.full, file = "Figure-3.pdf", height = 6, width = 10)




### KRLS models (mean values)

krls.median.div.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
             X = na.omit(subset(repfile, dividedpressenate == 1, 
                                select = c(fealty.ols.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
             print.level = 0))

krls.median.uni.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
             X = na.omit(subset(repfile, dividedpressenate == 0, 
                                select = c(fealty.ols.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
             print.level = 0))

krls.median.div.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
             X = na.omit(subset(repfile, dividedpressenate == 1, 
                                select = c(fealty.efa.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
             print.level = 0))

krls.median.uni.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
             X = na.omit(subset(repfile, dividedpressenate == 0, 
                                select = c(fealty.efa.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
             print.level = 0))



krls.fil.div.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                      X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                         select = c(fealty.ols.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                      print.level = 0))

krls.fil.uni.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                      X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                         select = c(fealty.ols.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                      print.level = 0))

krls.fil.div.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                      X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                         select = c(fealty.efa.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                      print.level = 0))

krls.fil.uni.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                      X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                         select = c(fealty.efa.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                      print.level = 0))


krls.comm.div.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                   X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zprescommdist), 
                                                      select = c(fealty.ols.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                   print.level = 0))

krls.comm.uni.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                   X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zprescommdist), 
                                                      select = c(fealty.ols.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                   print.level = 0))

krls.comm.div.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                   X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zprescommdist), 
                                                      select = c(fealty.efa.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                   print.level = 0))

krls.comm.uni.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                   X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zprescommdist), 
                                                      select = c(fealty.efa.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                   print.level = 0))


krls.chair.div.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                    X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zpreschairdist), 
                                                       select = c(fealty.ols.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                    print.level = 0))

krls.chair.uni.ols.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                    X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zpreschairdist), 
                                                       select = c(fealty.ols.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                    print.level = 0))

krls.chair.div.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                    X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zpreschairdist), 
                                                       select = c(fealty.efa.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                    print.level = 0))

krls.chair.uni.efa.mean.mod <- (krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                    X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zpreschairdist), 
                                                       select = c(fealty.efa.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                    print.level = 0))


htmlreg(file = "Table-A1.doc",
        list(extract.krls(krls.median.uni.ols.mean.mod),
               extract.krls(krls.median.div.ols.mean.mod),
               extract.krls(krls.median.uni.efa.mean.mod),
               extract.krls(krls.median.div.efa.mean.mod)),
          custom.coef.names = c("Fealty (Regression-Based Scores)",
                                "President-Senate Median Ideological Divergence",
                                "Senate Polarization",
                                "Congress",
                                "Supervisory Position",
                                "Presidentially-Aligned Agency",
                                "Presidentially-Opposed Agency",
                                "Priority Agency",
                                "Presidential Approval", 
                                "Policy Expertise",
                                "Fealty (EFA-Based Scores)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))

htmlreg(file = "Table-A2.doc",
        list(extract.krls.quartile(krls.median.uni.ols.mean.mod),
             extract.krls.quartile(krls.median.div.ols.mean.mod),
             extract.krls.quartile(krls.median.uni.efa.mean.mod),
             extract.krls.quartile(krls.median.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A2.doc",
        list(extract.krls(krls.fil.uni.ols.mean.mod),
               extract.krls(krls.fil.div.ols.mean.mod),
               extract.krls(krls.fil.uni.efa.mean.mod),
               extract.krls(krls.fil.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A6.doc",
        list(extract.krls.quartile(krls.fil.uni.ols.mean.mod),
             extract.krls.quartile(krls.fil.div.ols.mean.mod),
             extract.krls.quartile(krls.fil.uni.efa.mean.mod),
             extract.krls.quartile(krls.fil.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A4.doc",
        list(extract.krls(krls.comm.uni.ols.mean.mod),
             extract.krls(krls.comm.div.ols.mean.mod),
             extract.krls(krls.comm.uni.efa.mean.mod),
             extract.krls(krls.comm.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A8.doc",
        list(extract.krls.quartile(krls.comm.uni.ols.mean.mod),
             extract.krls.quartile(krls.comm.div.ols.mean.mod),
             extract.krls.quartile(krls.comm.uni.efa.mean.mod),
             extract.krls.quartile(krls.comm.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A3.doc",
        list(extract.krls(krls.chair.uni.ols.mean.mod),
             extract.krls(krls.chair.div.ols.mean.mod),
             extract.krls(krls.chair.uni.efa.mean.mod),
             extract.krls(krls.chair.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A7.doc",
        list(extract.krls.quartile(krls.chair.uni.ols.mean.mod),
             extract.krls.quartile(krls.chair.div.ols.mean.mod),
             extract.krls.quartile(krls.chair.uni.efa.mean.mod),
             extract.krls.quartile(krls.chair.div.efa.mean.mod)),
        custom.coef.names = c("Fealty (Regression-Based Scores)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval", 
                              "Policy Expertise",
                              "Fealty (EFA-Based Scores)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


# making plots
krls.median.mean.frame <- data.frame(Distance = c(repfile$zpressendist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpressendist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpressendist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpressendist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]),
                              Derivative = c(krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                                     select = c(fealty.ols.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                                     select = c(fealty.efa.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                                     select = c(fealty.ols.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                                     select = c(fealty.efa.mean, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1]),
                              Estimator = c(rep("OLS", length(repfile$zpressendist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                            rep("EFA", length(repfile$zpressendist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                            rep("OLS", length(repfile$zpressendist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))])),
                                            rep("EFA", length(repfile$zpressendist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]))),
                              Divided = c(rep("Unified Government", 2*length(repfile$zpressendist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                          rep("Divided Government", 2*length(repfile$zpressendist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]))))



krls.fil.mean.frame <- data.frame(Distance = c(repfile$zpresfildist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpresfildist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpresfildist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))],
                                           repfile$zpresfildist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]),
                              Derivative = c(krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                                     select = c(fealty.ols.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 0, 
                                                                     select = c(fealty.efa.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                                     select = c(fealty.ols.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1],
                                             krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                                  X = na.omit(subset(repfile, dividedpressenate == 1, 
                                                                     select = c(fealty.efa.mean, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                  print.level = 0)$derivatives[,1]),
                              Estimator = c(rep("OLS", length(repfile$zpresfildist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                            rep("EFA", length(repfile$zpresfildist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                            rep("OLS", length(repfile$zpresfildist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))])),
                                            rep("EFA", length(repfile$zpresfildist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]))),
                              Divided = c(rep("Unified Government", 2*length(repfile$zpresfildist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))])),
                                          rep("Divided Government", 2*length(repfile$zpresfildist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))]))))



krls.comm.mean.frame <- data.frame(Distance = c(repfile$zprescommdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))],
                                                repfile$zprescommdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))],
                                                repfile$zprescommdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))],
                                                repfile$zprescommdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))]),
                                   Derivative = c(krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                                       X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zprescommdist), 
                                                                          select = c(fealty.ols.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                       print.level = 0)$derivatives[,1],
                                                  krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                                       X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zprescommdist), 
                                                                          select = c(fealty.efa.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                       print.level = 0)$derivatives[,1],
                                                  krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                                       X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zprescommdist), 
                                                                          select = c(fealty.ols.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                       print.level = 0)$derivatives[,1],
                                                  krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                                       X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zprescommdist), 
                                                                          select = c(fealty.efa.mean, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                       print.level = 0)$derivatives[,1]),
                                   Estimator = c(rep("OLS", length(repfile$zprescommdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))])),
                                                 rep("EFA", length(repfile$zprescommdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))])),
                                                 rep("OLS", length(repfile$zprescommdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))])),
                                                 rep("EFA", length(repfile$zprescommdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))]))),
                                   Divided = c(rep("Unified Government", 2*length(repfile$zprescommdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))])),
                                               rep("Divided Government", 2*length(repfile$zprescommdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))]))))



krls.chair.mean.frame <- data.frame(Distance = c(repfile$zpreschairdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))],
                                                 repfile$zpreschairdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))],
                                                 repfile$zpreschairdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))],
                                                 repfile$zpreschairdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))]),
                                    Derivative = c(krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                                        X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zpreschairdist), 
                                                                           select = c(fealty.ols.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                        print.level = 0)$derivatives[,1],
                                                   krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                                        X = na.omit(subset(repfile, dividedpressenate == 0 & !is.na(repfile$zpreschairdist), 
                                                                           select = c(fealty.efa.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                        print.level = 0)$derivatives[,1],
                                                   krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                                        X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zpreschairdist), 
                                                                           select = c(fealty.ols.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                        print.level = 0)$derivatives[,1],
                                                   krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                                        X = na.omit(subset(repfile, dividedpressenate == 1 & !is.na(repfile$zpreschairdist), 
                                                                           select = c(fealty.efa.mean, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.mean))),
                                                        print.level = 0)$derivatives[,1]),
                                    Estimator = c(rep("OLS", length(repfile$zpreschairdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))])),
                                                  rep("EFA", length(repfile$zpreschairdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))])),
                                                  rep("OLS", length(repfile$zpreschairdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))])),
                                                  rep("EFA", length(repfile$zpreschairdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))]))),
                                    Divided = c(rep("Unified Government", 2*length(repfile$zpreschairdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))])),
                                                rep("Divided Government", 2*length(repfile$zpreschairdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))]))))


krls.median.mean.frame$Divided <- factor(krls.median.mean.frame$Divided, levels = c("Unified Government", "Divided Government"))
krls.fil.mean.frame$Divided <- factor(krls.fil.mean.frame$Divided, levels = c("Unified Government", "Divided Government"))
krls.comm.mean.frame$Divided <- factor(krls.comm.mean.frame$Divided, levels = c("Unified Government", "Divided Government"))
krls.chair.mean.frame$Divided <- factor(krls.chair.mean.frame$Divided, levels = c("Unified Government", "Divided Government"))

krls.median.mean.frame$Estimator <- factor(krls.median.mean.frame$Estimator, labels = c("Exploratory Factor Analysis\n(Two-Factor)", 
                                                                                        "Regression-Based\n(Original Krause & O'Connell Scores)"))

krls.fil.mean.frame$Estimator <- factor(krls.fil.mean.frame$Estimator, labels = c("Exploratory Factor Analysis\n(Two-Factor)", 
                                                                                  "Regression-Based\n(Original Krause & O'Connell Scores)"))

krls.comm.mean.frame$Estimator <- factor(krls.comm.mean.frame$Estimator, labels = c("Exploratory Factor Analysis\n(Two-Factor)", 
                                                                                    "Regression-Based\n(Original Krause & O'Connell Scores)"))

krls.chair.mean.frame$Estimator <- factor(krls.chair.mean.frame$Estimator, labels = c("Exploratory Factor Analysis\n(Two-Factor)", 
                                                                                      "Regression-Based\n(Original Krause & O'Connell Scores)"))


krls.median.mean.frame$Estimator <- factor(krls.median.mean.frame$Estimator, levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                        "Exploratory Factor Analysis\n(Two-Factor)"))

krls.fil.mean.frame$Estimator <- factor(krls.fil.mean.frame$Estimator, levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                  "Exploratory Factor Analysis\n(Two-Factor)"))

krls.comm.mean.frame$Estimator <- factor(krls.comm.mean.frame$Estimator, levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                    "Exploratory Factor Analysis\n(Two-Factor)"))

krls.chair.mean.frame$Estimator <- factor(krls.chair.mean.frame$Estimator, levels = c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                      "Exploratory Factor Analysis\n(Two-Factor)"))

# do levels for pivots
# relabel axes in plots to account for switch in variables


krls.median.mean.frame$SD_Derivative <- krls.median.mean.frame$Derivative
krls.median.mean.frame$SD_Derivative[krls.median.mean.frame$Divided == "Unified Government" & 
                                       krls.median.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.median.mean.frame$Derivative[krls.median.mean.frame$Divided == "Unified Government" & 
                                      krls.median.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])
krls.median.mean.frame$SD_Derivative[krls.median.mean.frame$Divided == "Divided Government" & 
                                       krls.median.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.median.mean.frame$Derivative[krls.median.mean.frame$Divided == "Divided Government" & 
                                      krls.median.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])

krls.median.mean.frame$SD_Derivative[krls.median.mean.frame$Divided == "Unified Government" & 
                                       krls.median.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.median.mean.frame$Derivative[krls.median.mean.frame$Divided == "Unified Government" & 
                                      krls.median.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                      !is.na(repfile$presallyagencyideol))])
krls.median.mean.frame$SD_Derivative[krls.median.mean.frame$Divided == "Divided Government" & 
                                       krls.median.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.median.mean.frame$Derivative[krls.median.mean.frame$Divided == "Divided Government" & 
                                      krls.median.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                      !is.na(repfile$presallyagencyideol))])

krls.fil.mean.frame$SD_Derivative <- krls.fil.mean.frame$Derivative
krls.fil.mean.frame$SD_Derivative[krls.fil.mean.frame$Divided == "Unified Government" & 
                                    krls.fil.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.fil.mean.frame$Derivative[krls.fil.mean.frame$Divided == "Unified Government" & 
                                   krls.fil.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                            !is.na(repfile$presallyagencyideol))])
krls.fil.mean.frame$SD_Derivative[krls.fil.mean.frame$Divided == "Divided Government" & 
                                    krls.fil.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.fil.mean.frame$Derivative[krls.fil.mean.frame$Divided == "Divided Government" & 
                                   krls.fil.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                            !is.na(repfile$presallyagencyideol))])

krls.fil.mean.frame$SD_Derivative[krls.fil.mean.frame$Divided == "Unified Government" & 
                                    krls.fil.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.fil.mean.frame$Derivative[krls.fil.mean.frame$Divided == "Unified Government" & 
                                   krls.fil.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                !is.na(repfile$presallyagencyideol))])
krls.fil.mean.frame$SD_Derivative[krls.fil.mean.frame$Divided == "Divided Government" & 
                                    krls.fil.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.fil.mean.frame$Derivative[krls.fil.mean.frame$Divided == "Divided Government" & 
                                   krls.fil.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                !is.na(repfile$presallyagencyideol))])


krls.comm.mean.frame$SD_Derivative <- krls.comm.mean.frame$Derivative
krls.comm.mean.frame$SD_Derivative[krls.comm.mean.frame$Divided == "Unified Government" & 
                                     krls.comm.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.comm.mean.frame$Derivative[krls.comm.mean.frame$Divided == "Unified Government" & 
                                    krls.comm.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                              !is.na(repfile$presallyagencyideol))])
krls.comm.mean.frame$SD_Derivative[krls.comm.mean.frame$Divided == "Divided Government" & 
                                     krls.comm.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.comm.mean.frame$Derivative[krls.comm.mean.frame$Divided == "Divided Government" & 
                                    krls.comm.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                              !is.na(repfile$presallyagencyideol))])

krls.comm.mean.frame$SD_Derivative[krls.comm.mean.frame$Divided == "Unified Government" & 
                                     krls.comm.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.comm.mean.frame$Derivative[krls.comm.mean.frame$Divided == "Unified Government" & 
                                    krls.comm.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])
krls.comm.mean.frame$SD_Derivative[krls.comm.mean.frame$Divided == "Divided Government" & 
                                     krls.comm.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.comm.mean.frame$Derivative[krls.comm.mean.frame$Divided == "Divided Government" & 
                                    krls.comm.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])




krls.chair.mean.frame$SD_Derivative <- krls.chair.mean.frame$Derivative
krls.chair.mean.frame$SD_Derivative[krls.chair.mean.frame$Divided == "Unified Government" & 
                                      krls.chair.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.chair.mean.frame$Derivative[krls.chair.mean.frame$Divided == "Unified Government" & 
                                     krls.chair.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                                !is.na(repfile$presallyagencyideol))])
krls.chair.mean.frame$SD_Derivative[krls.chair.mean.frame$Divided == "Divided Government" & 
                                      krls.chair.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.chair.mean.frame$Derivative[krls.chair.mean.frame$Divided == "Divided Government" & 
                                     krls.chair.mean.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                                !is.na(repfile$presallyagencyideol))])

krls.chair.mean.frame$SD_Derivative[krls.chair.mean.frame$Divided == "Unified Government" & 
                                      krls.chair.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.chair.mean.frame$Derivative[krls.chair.mean.frame$Divided == "Unified Government" & 
                                     krls.chair.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                    !is.na(repfile$presallyagencyideol))])
krls.chair.mean.frame$SD_Derivative[krls.chair.mean.frame$Divided == "Divided Government" & 
                                      krls.chair.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.chair.mean.frame$Derivative[krls.chair.mean.frame$Divided == "Divided Government" & 
                                     krls.chair.mean.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                    !is.na(repfile$presallyagencyideol))])



krls.median.mean.frame$Rescaled <- krls.median.mean.frame$Distance
krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Unified Government"] <- scales::rescale(ecdf(unique(krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Unified Government"]))(krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Unified Government"]), to = c(0,100))
krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Divided Government"] <- scales::rescale(ecdf(unique(krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Divided Government"]))(krls.median.mean.frame$Rescaled[krls.median.mean.frame$Divided == "Divided Government"]), to = c(0,100))

krls.fil.mean.frame$Rescaled <- krls.fil.mean.frame$Distance
krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Unified Government"] <- scales::rescale(ecdf(unique(krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Unified Government"]))(krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Unified Government"]), to = c(0,100))
krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Divided Government"] <- scales::rescale(ecdf(unique(krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Divided Government"]))(krls.fil.mean.frame$Rescaled[krls.fil.mean.frame$Divided == "Divided Government"]), to = c(0,100))

krls.comm.mean.frame$Rescaled <- krls.comm.mean.frame$Distance
krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Unified Government"] <- scales::rescale(ecdf(unique(krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Unified Government"]))(krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Unified Government"]), to = c(0,100))
krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Divided Government"] <- scales::rescale(ecdf(unique(krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Divided Government"]))(krls.comm.mean.frame$Rescaled[krls.comm.mean.frame$Divided == "Divided Government"]), to = c(0,100))

krls.chair.mean.frame$Rescaled <- krls.chair.mean.frame$Distance
krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Unified Government"] <- scales::rescale(ecdf(unique(krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Unified Government"]))(krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Unified Government"]), to = c(0,100))
krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Divided Government"] <- scales::rescale(ecdf(unique(krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Divided Government"]))(krls.chair.mean.frame$Rescaled[krls.chair.mean.frame$Divided == "Divided Government"]), to = c(0,100))


krls.all.mean.frame <- rbind(data.frame(krls.median.mean.frame, Pivot = "Senate Median"),
                             data.frame(krls.fil.mean.frame, Pivot = "Filbuster Pivot"),
                             data.frame(krls.chair.mean.frame, Pivot = "Committee Chair"),
                             data.frame(krls.comm.mean.frame, Pivot = "Committee Median"))

krls.all.mean.frame$Pivot <-  factor(krls.all.mean.frame$Pivot, levels = c("Senate Median", "Filbuster Pivot", "Committee Chair", "Committee Median"))

krls.all.mean.plot <- ggplot(krls.all.mean.frame, 
                             aes(x = Rescaled, y = SD_Derivative, linetype = Estimator, fill = Estimator)) + 
  geom_hline(yintercept = 0, linetype = "dotted") + 
  stat_smooth(formula = "y ~ x", method = "loess", color = "black", alpha = 0.25, size = .5) + 
  stat_smooth(formula = "y ~ x", method = "loess", color = "black", level = 0.9, alpha = 0.75, size = .5) + 
  facet_grid(Divided ~ Pivot) + 
  theme_bw() +         
  xlab('\nAbsolute President-Senate Pivot Ideological Divergence\n(Percentile Conditional on Pivot and Unified/Divided Status)') + 
  ylab('Estimated Marginal Effect of Fealty on President-Appointee Divergence\n(Standardized by the Standard Deviation of Divergence)\n') + 
  scale_linetype_manual(values = c(1,2), labels = c("Regression-Based", "Exploratory Factor Analysis")) + scale_fill_grey(start = 0.3, end = 0.7, labels = c("Regression-Based", "Exploratory Factor Analysis")) + 
  theme(legend.position="bottom", legend.box="vertical", legend.margin=margin(), 
        axis.text.x = element_text(angle = 45, vjust =1 , hjust=1)) 




ggsave(krls.all.mean.plot, file = "Figure-1.pdf", height = 6, width = 8)
ggsave(krls.all.mean.plot, file = "Figure-1.png", height = 6, width = 8)



### complement/substitute plot
set.seed(1)
hypoplot.frame <-  data.frame(Fealty = runif(1000, 0, 1),
                              Shared = runif(1000, 0, 1))

hypoplot <- ggplot(hypoplot.frame, aes(x = Fealty, y = Shared)) + 
  annotate(geom = "rect", xmin=0, xmax=1/3, ymin=0, ymax=1/3, fill = "red", alpha = 0.2) + 
  annotate(geom = "rect", xmin=2/3, xmax=1, ymin=2/3, ymax=1, fill = "red", alpha = 0.2) + 
  annotate(geom = "rect", xmin=0, xmax=1/3, ymin=2/3, ymax=1, fill = "blue", alpha = 0.2) + 
  annotate(geom = "rect", xmin=2/3, xmax=1, ymin=0, ymax=1/3, fill = "blue", alpha = 0.2) + 
  geom_hline(yintercept = 1/3, linetype = "dashed") + 
  geom_hline(yintercept = 2/3, linetype = "dashed") + 
  geom_vline(xintercept = 1/3, linetype = "dashed") + 
  geom_vline(xintercept = 2/3, linetype = "dashed") + 
  theme_bw() + 
  annotate(x = 1/6, y = 1/6, geom = "text", label = "Substitutes") + 
  annotate(x = 5/6, y = 5/6, geom = "text", label = "Substitutes") + 
  annotate(x = 1/6, y = 5/6, geom = "text", label = "Complements") + 
  annotate(x = 5/6, y = 1/6, geom = "text", label = "Complements") + 
  annotate(x = 1/2, y = 1/6, geom = "text", label = "Neither") + 
  annotate(x = 1/2, y = 5/6, geom = "text", label = "Neither") + 
  annotate(x = 1/6, y = 1/2, geom = "text", label = "Neither") + 
  annotate(x = 5/6, y = 1/2, geom = "text", label = "Neither") + 
  annotate(x = 1/2, y = 1/2, geom = "text", label = "Neither") + 
  scale_x_continuous(limits = c(0,1), expand = c(0,0), breaks = c(0, 1/3, 2/3, 1), labels = c("0", "1/3", "2/3", "1")) + 
  scale_y_continuous(limits = c(0,1), expand = c(0,0), breaks = c(0, 1/3, 2/3, 1), labels = c("0", "1/3", "2/3", "1")) + 
  xlab("\nFealty Percentile") + ylab("Ideological Divergence Percentile\n")

ggsave(hypoplot, file = "Figure-2.pdf", height = 5, width = 5)
ggsave(hypoplot, file = "Figure-2.png", height = 5, width = 5)




##### use the posterior distributions to make charts
predsframe.median.ols.tercile <- NULL
predsframe.median.efa.tercile <- NULL
predsframe.fil.ols.tercile <- NULL
predsframe.fil.efa.tercile <- NULL
predsframe.comm.ols.tercile <- NULL
predsframe.comm.efa.tercile <- NULL
predsframe.chair.ols.tercile <- NULL
predsframe.chair.efa.tercile <- NULL

list.median.ols.tercile <- vector(mode = "list", length = 1000)
list.median.efa.tercile <- vector(mode = "list", length = 1000)
list.fil.ols.tercile <- vector(mode = "list", length = 1000)
list.fil.efa.tercile <- vector(mode = "list", length = 1000)
list.comm.ols.tercile <- vector(mode = "list", length = 1000)
list.comm.efa.tercile <- vector(mode = "list", length = 1000)
list.chair.ols.tercile <- vector(mode = "list", length = 1000)
list.chair.efa.tercile <- vector(mode = "list", length = 1000)



for(i in 1:1000){
  fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  repfile$fealtyideocomp.tercile.ols <- 0
  repfile$fealtyideocomp.tercile.efa <- 0
  repfile$fealtyideosub.tercile.ols <- 0
  repfile$fealtyideosub.tercile.efa <- 0

  # OLS on KO estimates
  repfile$fealtyideocomp.tercile.ols <- as.numeric(with(repfile, fealty.ols.foo >= quantile(fealty.ols.foo, c(1/3,2/3), na.rm = T)[2] & 
                                                        zpresnomdist <= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[1])) + 
    as.numeric(with(repfile, fealty.ols.foo <= quantile(fealty.ols.foo, c(1/3,2/3), na.rm = T)[1] & 
                      zpresnomdist >= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[2]))
  repfile$fealtyideosub.tercile.ols <- as.numeric(with(repfile, fealty.ols.foo >= quantile(fealty.ols.foo, c(1/3,2/3), na.rm = T)[2] & 
                                                       zpresnomdist >= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[2])) + 
    as.numeric(with(repfile, fealty.ols.foo <= quantile(fealty.ols.foo, c(1/3,2/3), na.rm = T)[1] & 
                      zpresnomdist <= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[1]))
  
  repfile$fealtyboth.tercile.ols <- repfile$fealtyideocomp.tercile.ols - repfile$fealtyideosub.tercile.ols

  # EFA
  repfile$fealtyideocomp.tercile.efa <- as.numeric(with(repfile, fealty.efa.foo >= quantile(fealty.efa.foo, c(1/3,2/3), na.rm = T)[2] & 
                                                                zpresnomdist <= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[1])) + 
    as.numeric(with(repfile, fealty.efa.foo <= quantile(fealty.efa.foo, c(1/3,2/3), na.rm = T)[1] & 
                      zpresnomdist >= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[2]))
  repfile$fealtyideosub.tercile.efa <- as.numeric(with(repfile, fealty.efa.foo >= quantile(fealty.efa.foo, c(1/3,2/3), na.rm = T)[2] & 
                                                               zpresnomdist >= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[2])) + 
    as.numeric(with(repfile, fealty.efa.foo <= quantile(fealty.efa.foo, c(1/3,2/3), na.rm = T)[1] & 
                      zpresnomdist <= quantile(zpresnomdist, c(1/3,2/3), na.rm = T)[1]))

    repfile$fealtyboth.tercile.efa <- repfile$fealtyideocomp.tercile.efa - repfile$fealtyideosub.tercile.efa

  try(mod.median.ols.tercile <- polr(as.factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.fil.ols.tercile <- polr(as.factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.comm.ols.tercile <- polr(as.factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.chair.ols.tercile <- polr(as.factor(fealtyboth.tercile.ols) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))

  try(mod.median.efa.tercile <- polr(as.factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.fil.efa.tercile <- polr(as.factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.comm.efa.tercile <- polr(as.factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))
  try(mod.chair.efa.tercile <- polr(as.factor(fealtyboth.tercile.efa) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.foo, repfile))



  list.median.ols.tercile[[i]] <- mod.median.ols.tercile
  list.median.efa.tercile[[i]] <- mod.median.efa.tercile
  list.fil.ols.tercile[[i]] <- mod.fil.ols.tercile
  list.fil.efa.tercile[[i]] <- mod.fil.efa.tercile
  list.comm.ols.tercile[[i]] <- mod.comm.ols.tercile
  list.comm.efa.tercile[[i]] <- mod.comm.efa.tercile
  list.chair.ols.tercile[[i]] <- mod.chair.ols.tercile
  list.chair.efa.tercile[[i]] <- mod.chair.efa.tercile

  try(predsframe.median.ols.tercile <- rbind(predsframe.median.ols.tercile,
                                         cbind(i, 
                                               rbind(data.frame(Effect(c("zpressendist"), 
                                                                       mod.median.ols.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_unified_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[6]],
                                                                Effect(c("zpressendist"), 
                                                                       mod.median.ols.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_unified_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[11]],
                                                                Divided = 0),
                                                     data.frame(Effect(c("zpressendist"), 
                                                                       mod.median.ols.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_divided_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[6]],
                                                                Effect(c("zpressendist"), 
                                                                       mod.median.ols.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_divided_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[11]],
                                                                Divided = 1)))))
  
  try(predsframe.median.efa.tercile <- rbind(predsframe.median.efa.tercile,
                                         cbind(i, 
                                               rbind(data.frame(Effect(c("zpressendist"), 
                                                                       mod.median.efa.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_unified_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[6]],
                                                                Effect(c("zpressendist"), 
                                                                       mod.median.efa.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_unified_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[11]],
                                                                Divided = 0),
                                                     data.frame(Effect(c("zpressendist"), 
                                                                       mod.median.efa.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_divided_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[6]],
                                                                Effect(c("zpressendist"), 
                                                                       mod.median.efa.tercile, 
                                                                       xlevels = list("zpressendist" = seq_alt_divided_med), 
                                                                       fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                              "toplevel2" = 0, 
                                                                                                              "soucountagency1" = 1,
                                                                                                              "approval" = 55,
                                                                                                              "presalignedagency" = 0, 
                                                                                                              "presopposedagency" = 0,
                                                                                                              "policy.foo" = 0)), 
                                                                       se = TRUE)[[11]],
                                                                Divided = 1)))))
  
  try(predsframe.comm.ols.tercile <- rbind(predsframe.comm.ols.tercile,
                                       cbind(i, 
                                             rbind(data.frame(Effect(c("zprescommdist"), 
                                                                     mod.comm.ols.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_unified_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[6]],
                                                              Effect(c("zprescommdist"), 
                                                                     mod.comm.ols.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_unified_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[11]],
                                                              Divided = 0),
                                                   data.frame(Effect(c("zprescommdist"), 
                                                                     mod.comm.ols.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_divided_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[6]],
                                                              Effect(c("zprescommdist"), 
                                                                     mod.comm.ols.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_divided_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[11]],
                                                              Divided = 1)))))
  
  try(predsframe.comm.efa.tercile <- rbind(predsframe.comm.efa.tercile,
                                       cbind(i, 
                                             rbind(data.frame(Effect(c("zprescommdist"), 
                                                                     mod.comm.efa.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_unified_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[6]],
                                                              Effect(c("zprescommdist"), 
                                                                     mod.comm.efa.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_unified_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[11]],
                                                              Divided = 0),
                                                   data.frame(Effect(c("zprescommdist"), 
                                                                     mod.comm.efa.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_divided_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[6]],
                                                              Effect(c("zprescommdist"), 
                                                                     mod.comm.efa.tercile, 
                                                                     xlevels = list("zprescommdist" = seq_alt_divided_com), 
                                                                     fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                            "toplevel2" = 0, 
                                                                                                            "soucountagency1" = 1,
                                                                                                            "approval" = 55,
                                                                                                            "presalignedagency" = 0, 
                                                                                                            "presopposedagency" = 0,
                                                                                                            "policy.foo" = 0)), 
                                                                     se = TRUE)[[11]],
                                                              Divided = 1)))))
  
  try(predsframe.fil.ols.tercile <- rbind(predsframe.fil.ols.tercile,
                                      cbind(i, 
                                            rbind(data.frame(Effect(c("zpresfildist"), 
                                                                    mod.fil.ols.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_unified_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[6]],
                                                             Effect(c("zpresfildist"), 
                                                                    mod.fil.ols.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_unified_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[11]],
                                                             Divided = 0),
                                                  data.frame(Effect(c("zpresfildist"), 
                                                                    mod.fil.ols.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_divided_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[6]],
                                                             Effect(c("zpresfildist"), 
                                                                    mod.fil.ols.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_divided_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[11]],
                                                             Divided = 1)))))
  
  try(predsframe.fil.efa.tercile <- rbind(predsframe.fil.efa.tercile,
                                      cbind(i, 
                                            rbind(data.frame(Effect(c("zpresfildist"), 
                                                                    mod.fil.efa.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_unified_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[6]],
                                                             Effect(c("zpresfildist"), 
                                                                    mod.fil.efa.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_unified_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[11]],
                                                             Divided = 0),
                                                  data.frame(Effect(c("zpresfildist"), 
                                                                    mod.fil.efa.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_divided_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[6]],
                                                             Effect(c("zpresfildist"), 
                                                                    mod.fil.efa.tercile, 
                                                                    xlevels = list("zpresfildist" = seq_alt_divided_fil), 
                                                                    fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                           "toplevel2" = 0, 
                                                                                                           "soucountagency1" = 1,
                                                                                                           "approval" = 55,
                                                                                                           "presalignedagency" = 0, 
                                                                                                           "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                    se = TRUE)[[11]],
                                                             Divided = 1)))))
  
  try(predsframe.chair.ols.tercile <- rbind(predsframe.chair.ols.tercile,
                                        cbind(i, 
                                              rbind(data.frame(Effect(c("zpreschairdist"), 
                                                                      mod.chair.ols.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_unified_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[6]],
                                                               Effect(c("zpreschairdist"), 
                                                                      mod.chair.ols.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_unified_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[11]],
                                                               Divided = 0),
                                                    data.frame(Effect(c("zpreschairdist"), 
                                                                      mod.chair.ols.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_divided_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[6]],
                                                               Effect(c("zpreschairdist"), 
                                                                      mod.chair.ols.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_divided_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[11]],
                                                               Divided = 1)))))
  
  try(predsframe.chair.efa.tercile <- rbind(predsframe.chair.efa.tercile,
                                        cbind(i, 
                                              rbind(data.frame(Effect(c("zpreschairdist"), 
                                                                      mod.chair.efa.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_unified_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[6]],
                                                               Effect(c("zpreschairdist"), 
                                                                      mod.chair.efa.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_unified_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 0, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[11]],
                                                               Divided = 0),
                                                    data.frame(Effect(c("zpreschairdist"), 
                                                                      mod.chair.efa.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_divided_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[6]],
                                                               Effect(c("zpreschairdist"), 
                                                                      mod.chair.efa.tercile, 
                                                                      xlevels = list("zpreschairdist" = seq_alt_divided_cha), 
                                                                      fixed.predictors = list(given.values=c("dividedpressenate" = 1, 
                                                                                                             "toplevel2" = 0, 
                                                                                                             "soucountagency1" = 1,
                                                                                                             "approval" = 55,
                                                                                                             "presalignedagency" = 0, 
                                                                                                             "presopposedagency" = 0, "policy.foo" = 0)), 
                                                                      se = TRUE)[[11]],
                                                               Divided = 1)))))
  
  print(i)
  }




colnames(predsframe.median.ols.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")
colnames(predsframe.median.efa.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")

colnames(predsframe.fil.ols.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")
colnames(predsframe.fil.efa.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")

colnames(predsframe.comm.ols.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")
colnames(predsframe.comm.efa.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")

colnames(predsframe.chair.ols.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")
colnames(predsframe.chair.efa.tercile) <- c("i", "Distance", "Substitutes", "Neither", "Complements", "Divided")

predsframe.median.ols.tercile <- as.data.frame(predsframe.median.ols.tercile)
predsframe.median.efa.tercile <- as.data.frame(predsframe.median.efa.tercile)

predsframe.fil.ols.tercile <- as.data.frame(predsframe.fil.ols.tercile)
predsframe.fil.efa.tercile <- as.data.frame(predsframe.fil.efa.tercile)

predsframe.comm.ols.tercile <- as.data.frame(predsframe.comm.ols.tercile)
predsframe.comm.efa.tercile <- as.data.frame(predsframe.comm.efa.tercile)

predsframe.chair.ols.tercile <- as.data.frame(predsframe.chair.ols.tercile)
predsframe.chair.efa.tercile <- as.data.frame(predsframe.chair.efa.tercile)

predsframe.median.ols.tercile$Divided <- factor(predsframe.median.ols.tercile$Divided)
predsframe.median.efa.tercile$Divided <- factor(predsframe.median.efa.tercile$Divided)

predsframe.fil.ols.tercile$Divided <- factor(predsframe.fil.ols.tercile$Divided)
predsframe.fil.efa.tercile$Divided <- factor(predsframe.fil.efa.tercile$Divided)

predsframe.comm.ols.tercile$Divided <- factor(predsframe.comm.ols.tercile$Divided)
predsframe.comm.efa.tercile$Divided <- factor(predsframe.comm.efa.tercile$Divided)

predsframe.chair.ols.tercile$Divided <- factor(predsframe.chair.ols.tercile$Divided)
predsframe.chair.efa.tercile$Divided <- factor(predsframe.chair.efa.tercile$Divided)


predsframe.median.ols.tercile$i <- factor(predsframe.median.ols.tercile$i)
predsframe.median.efa.tercile$i <- factor(predsframe.median.efa.tercile$i)

predsframe.fil.ols.tercile$i <- factor(predsframe.fil.ols.tercile$i)
predsframe.fil.efa.tercile$i <- factor(predsframe.fil.efa.tercile$i)

predsframe.comm.ols.tercile$i <- factor(predsframe.comm.ols.tercile$i)
predsframe.comm.efa.tercile$i <- factor(predsframe.comm.efa.tercile$i)

predsframe.chair.ols.tercile$i <- factor(predsframe.chair.ols.tercile$i)
predsframe.chair.efa.tercile$i <- factor(predsframe.chair.efa.tercile$i)

predsframe.median.ols.tercile$Diff <-predsframe.median.ols.tercile$Substitutes - predsframe.median.ols.tercile$Complements
predsframe.median.efa.tercile$Diff <-predsframe.median.efa.tercile$Substitutes - predsframe.median.efa.tercile$Complements

predsframe.fil.ols.tercile$Diff <-predsframe.fil.ols.tercile$Substitutes - predsframe.fil.ols.tercile$Complements
predsframe.fil.efa.tercile$Diff <-predsframe.fil.efa.tercile$Substitutes - predsframe.fil.efa.tercile$Complements

predsframe.comm.ols.tercile$Diff <-predsframe.comm.ols.tercile$Substitutes - predsframe.comm.ols.tercile$Complements
predsframe.comm.efa.tercile$Diff <-predsframe.comm.efa.tercile$Substitutes - predsframe.comm.efa.tercile$Complements

predsframe.chair.ols.tercile$Diff <-predsframe.chair.ols.tercile$Substitutes - predsframe.chair.ols.tercile$Complements
predsframe.chair.efa.tercile$Diff <-predsframe.chair.efa.tercile$Substitutes - predsframe.chair.efa.tercile$Complements





predsframe.median.ols.tercile.melt <- subset(melt(subset(predsframe.median.ols.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                             id.vars = c("i", "Divided", "Distance")),
                                        select = -c(variable))
predsframe.median.efa.tercile.melt <- subset(melt(subset(predsframe.median.efa.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                             id.vars = c("i", "Divided", "Distance")),
                                        select = -c(variable))

predsframe.fil.ols.tercile.melt <- subset(melt(subset(predsframe.fil.ols.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                          id.vars = c("i", "Divided", "Distance")),
                                     select = -c(variable))
predsframe.fil.efa.tercile.melt <- subset(melt(subset(predsframe.fil.efa.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                          id.vars = c("i", "Divided", "Distance")),
                                     select = -c(variable))

predsframe.comm.ols.tercile.melt <- subset(melt(subset(predsframe.comm.ols.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                           id.vars = c("i", "Divided", "Distance")),
                                      select = -c(variable))
predsframe.comm.efa.tercile.melt <- subset(melt(subset(predsframe.comm.efa.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                           id.vars = c("i", "Divided", "Distance")),
                                      select = -c(variable))

predsframe.chair.ols.tercile.melt <- subset(melt(subset(predsframe.chair.ols.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                            id.vars = c("i", "Divided", "Distance")),
                                       select = -c(variable))
predsframe.chair.efa.tercile.melt <- subset(melt(subset(predsframe.chair.efa.tercile, select = c("i", "Distance", "Divided", "Diff")), 
                                            id.vars = c("i", "Divided", "Distance")),
                                       select = -c(variable))




predsframe.median.ols.tercile.melt$Method <- "Tercile Approach"
predsframe.median.efa.tercile.melt$Method <- "Tercile Approach"
predsframe.median.ols.tercile.melt$Estimator <- "Regression-Based\n(Original Krause & O'Connell Scores)"
predsframe.median.efa.tercile.melt$Estimator <- "Exploratory Factor Analysis\n(Two-Factor)"
predsframe.median.ols.tercile.melt$Divided <- factor(predsframe.median.ols.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))
predsframe.median.efa.tercile.melt$Divided <- factor(predsframe.median.efa.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))

predsframe.fil.ols.tercile.melt$Method <- "Tercile Approach"
predsframe.fil.efa.tercile.melt$Method <- "Tercile Approach"
predsframe.fil.ols.tercile.melt$Estimator <- "Regression-Based\n(Original Krause & O'Connell Scores)"
predsframe.fil.efa.tercile.melt$Estimator <- "Exploratory Factor Analysis\n(Two-Factor)"
predsframe.fil.ols.tercile.melt$Divided <- factor(predsframe.fil.ols.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))
predsframe.fil.efa.tercile.melt$Divided <- factor(predsframe.fil.efa.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))

predsframe.comm.ols.tercile.melt$Method <- "Tercile Approach"
predsframe.comm.efa.tercile.melt$Method <- "Tercile Approach"
predsframe.comm.ols.tercile.melt$Estimator <- "Regression-Based\n(Original Krause & O'Connell Scores)"
predsframe.comm.efa.tercile.melt$Estimator <- "Exploratory Factor Analysis\n(Two-Factor)"
predsframe.comm.ols.tercile.melt$Divided <- factor(predsframe.comm.ols.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))
predsframe.comm.efa.tercile.melt$Divided <- factor(predsframe.comm.efa.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))

predsframe.chair.ols.tercile.melt$Method <- "Tercile Approach"
predsframe.chair.efa.tercile.melt$Method <- "Tercile Approach"
predsframe.chair.ols.tercile.melt$Estimator <- "Regression-Based\n(Original Krause & O'Connell Scores)"
predsframe.chair.efa.tercile.melt$Estimator <- "Exploratory Factor Analysis\n(Two-Factor)"
predsframe.chair.ols.tercile.melt$Divided <- factor(predsframe.chair.ols.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))
predsframe.chair.efa.tercile.melt$Divided <- factor(predsframe.chair.efa.tercile.melt$Divided, labels = c("Unified Government", "Divided Government"))


predsframe.median.tercile <- rbind(predsframe.median.ols.tercile.melt,
                                   predsframe.median.efa.tercile.melt)

predsframe.fil.tercile <- rbind(predsframe.fil.ols.tercile.melt,
                                predsframe.fil.efa.tercile.melt)

predsframe.comm.tercile <- rbind(predsframe.comm.ols.tercile.melt,
                                 predsframe.comm.efa.tercile.melt)

predsframe.chair.tercile <- rbind(predsframe.chair.ols.tercile.melt,
                                  predsframe.chair.efa.tercile.melt)



predsframe.median.tercile$Estimator <- factor(predsframe.median.tercile$Estimator, 
                                              levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                        "Exploratory Factor Analysis\n(Two-Factor)"))

predsframe.fil.tercile$Estimator <- factor(predsframe.fil.tercile$Estimator, 
                                           levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                     "Exploratory Factor Analysis\n(Two-Factor)"))

predsframe.comm.tercile$Estimator <- factor(predsframe.comm.tercile$Estimator, 
                                            levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                      "Exploratory Factor Analysis\n(Two-Factor)"))

predsframe.chair.tercile$Estimator <- factor(predsframe.chair.tercile$Estimator, 
                                             levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                       "Exploratory Factor Analysis\n(Two-Factor)"))


### rescale "pressendist" variable
unified_rescale_med <- function(x){(x - min(seq_alt_unified_med)) * 100 / (max(seq_alt_unified_med) - min(seq_alt_unified_med))}
divided_rescale_med <- function(x){(x - min(seq_alt_divided_med)) * 100 / (max(seq_alt_divided_med) - min(seq_alt_divided_med))}

unified_rescale_fil <- function(x){(x - min(seq_alt_unified_fil)) * 100 / (max(seq_alt_unified_fil) - min(seq_alt_unified_fil))}
divided_rescale_fil <- function(x){(x - min(seq_alt_divided_fil)) * 100 / (max(seq_alt_divided_fil) - min(seq_alt_divided_fil))}

unified_rescale_com <- function(x){(x - min(seq_alt_unified_com)) * 100 / (max(seq_alt_unified_com) - min(seq_alt_unified_com))}
divided_rescale_com <- function(x){(x - min(seq_alt_divided_com)) * 100 / (max(seq_alt_divided_com) - min(seq_alt_divided_com))}

unified_rescale_cha <- function(x){(x - min(seq_alt_unified_cha)) * 100 / (max(seq_alt_unified_cha) - min(seq_alt_unified_cha))}
divided_rescale_cha <- function(x){(x - min(seq_alt_divided_cha)) * 100 / (max(seq_alt_divided_cha) - min(seq_alt_divided_cha))}


predsframe.median.tercile$Distance[predsframe.median.tercile$Divided == "Divided Government"] <- divided_rescale_med(predsframe.median.tercile$Distance[predsframe.median.tercile$Divided == "Divided Government"])
predsframe.median.tercile$Distance[predsframe.median.tercile$Divided == "Unified Government"] <- unified_rescale_med(predsframe.median.tercile$Distance[predsframe.median.tercile$Divided == "Unified Government"])

predsframe.fil.tercile$Distance[predsframe.fil.tercile$Divided == "Divided Government"] <- divided_rescale_fil(predsframe.fil.tercile$Distance[predsframe.fil.tercile$Divided == "Divided Government"])
predsframe.fil.tercile$Distance[predsframe.fil.tercile$Divided == "Unified Government"] <- unified_rescale_fil(predsframe.fil.tercile$Distance[predsframe.fil.tercile$Divided == "Unified Government"])

predsframe.comm.tercile$Distance[predsframe.comm.tercile$Divided == "Divided Government"] <- divided_rescale_com(predsframe.comm.tercile$Distance[predsframe.comm.tercile$Divided == "Divided Government"])
predsframe.comm.tercile$Distance[predsframe.comm.tercile$Divided == "Unified Government"] <- unified_rescale_com(predsframe.comm.tercile$Distance[predsframe.comm.tercile$Divided == "Unified Government"])

predsframe.chair.tercile$Distance[predsframe.chair.tercile$Divided == "Divided Government"] <- divided_rescale_cha(predsframe.chair.tercile$Distance[predsframe.chair.tercile$Divided == "Divided Government"])
predsframe.chair.tercile$Distance[predsframe.chair.tercile$Divided == "Unified Government"] <- unified_rescale_cha(predsframe.chair.tercile$Distance[predsframe.chair.tercile$Divided == "Unified Government"])


tercile.median.plot <- ggplot(predsframe.median.tercile, aes(x = Distance, y = value, group = i)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_line(alpha = 0.025) + 
  theme_bw() + 
  facet_grid(Divided ~ Estimator) + 
  xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Probability of Substitutes Minus Probability of Complements\n') + 
  ylim(-1, 1)

tercile.fil.plot <- ggplot(predsframe.fil.tercile, aes(x = Distance, y = value, group = i)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_line(alpha = 0.025) + 
  theme_bw() + 
  facet_grid(Divided ~ Estimator) + 
  xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Probability of Substitutes Minus Probability of Complements\n') + 
  ylim(-1, 1)

tercile.comm.plot <- ggplot(predsframe.comm.tercile, aes(x = Distance, y = value, group = i)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_line(alpha = 0.025) + 
  theme_bw() + 
  facet_grid(Divided ~ Estimator) + 
  xlab('\nAbsolute President-Committee Median Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Probability of Substitutes Minus Probability of Complements\n') + 
  ylim(-1, 1)

tercile.chair.plot <- ggplot(predsframe.chair.tercile, aes(x = Distance, y = value, group = i)) +
  geom_hline(yintercept = 0, lty = "dotted") +
  geom_line(alpha = 0.025) + 
  theme_bw() + 
  facet_grid(Divided ~ Estimator) + 
  xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Probability of Substitutes Minus Probability of Complements\n') + 
  ylim(-1, 1)



### mfx plot
predsframe.median.tercile.mfx.frame <- ddply(predsframe.median.tercile, .(i, Divided, Method, Estimator), summarise,
                                             low25 = Distance[which.min(abs(Distance - 25))],
                                             high75 = Distance[which.min(abs(Distance - 75))],
                                             Diff = value[which.min(abs(Distance - 75))] - value[which.min(abs(Distance - 25))])

predsframe.median.tercile.mfx.frame <- ddply(predsframe.median.tercile.mfx.frame, .(Divided, Method, Estimator), summarise,
                                             low025 = quantile(Diff, 0.025), 
                                             low05 = quantile(Diff, 0.05),
                                             pred = median(Diff),
                                             high95 = quantile(Diff, 0.95),
                                             high975 = quantile(Diff, 0.975),
                                             Pivot = "Senate Median")

predsframe.fil.tercile.mfx.frame <- ddply(predsframe.fil.tercile, .(i, Divided, Method, Estimator), summarise,
                                          low25 = Distance[which.min(abs(Distance - 25))],
                                          high75 = Distance[which.min(abs(Distance - 75))],
                                          Diff = value[which.min(abs(Distance - 75))] - value[which.min(abs(Distance - 25))])

predsframe.fil.tercile.mfx.frame <- ddply(predsframe.fil.tercile.mfx.frame, .(Divided, Method, Estimator), summarise,
                                          low025 = quantile(Diff, 0.025), 
                                          low05 = quantile(Diff, 0.05),
                                          pred = median(Diff),
                                          high95 = quantile(Diff, 0.95),
                                          high975 = quantile(Diff, 0.975),
                                          Pivot = "Filibuster Pivot")

predsframe.comm.tercile.mfx.frame <- ddply(predsframe.comm.tercile, .(i, Divided, Method, Estimator), summarise,
                                           low25 = Distance[which.min(abs(Distance - 25))],
                                           high75 = Distance[which.min(abs(Distance - 75))],
                                           Diff = value[which.min(abs(Distance - 75))] - value[which.min(abs(Distance - 25))])

predsframe.comm.tercile.mfx.frame <- ddply(predsframe.comm.tercile.mfx.frame, .(Divided, Method, Estimator), summarise,
                                           low025 = quantile(Diff, 0.025), 
                                           low05 = quantile(Diff, 0.05),
                                           pred = median(Diff),
                                           high95 = quantile(Diff, 0.95),
                                           high975 = quantile(Diff, 0.975),
                                           Pivot = "Committee Median")

predsframe.chair.tercile.mfx.frame <- ddply(predsframe.chair.tercile, .(i, Divided, Method, Estimator), summarise,
                                            low25 = Distance[which.min(abs(Distance - 25))],
                                            high75 = Distance[which.min(abs(Distance - 75))],
                                            Diff = value[which.min(abs(Distance - 75))] - value[which.min(abs(Distance - 25))])

predsframe.chair.tercile.mfx.frame <- ddply(predsframe.chair.tercile.mfx.frame, .(Divided, Method, Estimator), summarise,
                                            low025 = quantile(Diff, 0.025), 
                                            low05 = quantile(Diff, 0.05),
                                            pred = median(Diff),
                                            high95 = quantile(Diff, 0.95),
                                            high975 = quantile(Diff, 0.975),
                                            Pivot = "Committee Chair")

predsframe.tercile.mfx.frame <- rbind(predsframe.median.tercile.mfx.frame,
                                      predsframe.fil.tercile.mfx.frame,
                                      predsframe.comm.tercile.mfx.frame,
                                      predsframe.chair.tercile.mfx.frame)


predsframe.tercile.mfx.frame$Pivot <- factor(predsframe.tercile.mfx.frame$Pivot,
                                             levels = c("Senate Median",
                                                        "Filibuster Pivot",
                                                        "Committee Chair",
                                                        "Committee Median"))



tercile.mfx.plot.posterior.small <- ggplot(subset(predsframe.tercile.mfx.frame, 
                                            Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)", 
                                                             "Exploratory Factor Analysis\n(Two-Factor)")), 
                                     aes(x = Pivot, y = pred, color = Estimator, shape = Estimator)) + 
  geom_hline(yintercept = 0, linetype = "dashed") + 
  geom_errorbar(aes(ymin = low025, ymax = high975),  
                position = position_dodge(width = 0.4), width = 0) + 
  geom_errorbar(aes(ymin = low05, ymax = high95),  
                position = position_dodge(width = 0.4), width = 0.3) + 
  facet_wrap(~ Divided) + 
  geom_point(position = position_dodge(width = 0.4), size = 2) + 
  theme_bw() + 
  theme(legend.position="bottom", legend.box="vertical", legend.margin=margin(), 
        axis.text.x = element_text(angle = 45, vjust =1 , hjust=1)) + 
  scale_colour_grey(start = 0, end = 0.5,
                    labels = c("Regression-Based",
                               "Exploratory Factor Analysis")) + 
  scale_shape_discrete(labels = c("Regression-Based",
                                  "Exploratory Factor Analysis")) + 
  xlab('\nPivot of Interest') + 
  ylab('Change in Difference in Probability\nof Substitutes Versus Probability of Complements\n')

ggsave(tercile.mfx.plot.posterior.small, file = "Figure-A5.pdf", height = 6, width = 8)
ggsave(tercile.mfx.plot.posterior.small, file = "Figure-A5.png", height = 6, width = 8)



### get the combined estimate
# do it manually and use sds of coefficient estimates as ses
htmlreg(file = "Table-A15a.doc",
        list(extract.pooled.polr(list.median.ols.tercile),
             extract.pooled.polr(list.median.efa.tercile)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Senate Median Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2"),
        reorder.coef = c(2, 3, 1, 11, 12, 6, 7, 5, 8, 9, 10, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores", "EFA-Based Scores"))


htmlreg(file = "Table-A15b.doc",
        list(extract.pooled.polr(list.fil.ols.tercile),
             extract.pooled.polr(list.fil.efa.tercile)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Filibuster Pivot Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Senate Median Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2"),
        reorder.coef = c(2, 3, 1, 11, 12, 6, 7, 5, 8, 9, 10, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores", "EFA-Based Scores"))

htmlreg(file = "Table-A16b.doc",
        list(extract.pooled.polr(list.comm.ols.tercile),
             extract.pooled.polr(list.comm.efa.tercile)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Committee Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Senate Median Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2"),
        reorder.coef = c(2, 3, 1, 11, 12, 6, 7, 5, 8, 9, 10, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores", "EFA-Based Scores"))

htmlreg(file = "Table-A16a.doc",
        list(extract.pooled.polr(list.chair.ols.tercile),
             extract.pooled.polr(list.chair.efa.tercile)),
        digits = 3, stars = c(0.01, 0.05, 0.1),
        custom.coef.names = c("Divided Government",
                              "President-Committee Chair Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "President-Senate Median Ideological Divergence x Divided Government",
                              "Senate Polarization x Divided Government",
                              "Cutpoint 1", 
                              "Cutpoint 2"),
        reorder.coef = c(2, 3, 1, 11, 12, 6, 7, 5, 8, 9, 10, 4, 13, 14),
        custom.model.names = c("OLS-Based Scores", "EFA-Based Scores"))


# KRLS Approach
# okay, let's get all of the lines
krls.median.uni.ols <- vector(mode = "list", length = 1000)
krls.median.div.ols <- vector(mode = "list", length = 1000)
krls.median.uni.efa <- vector(mode = "list", length = 1000)
krls.median.div.efa <- vector(mode = "list", length = 1000)

krls.fil.uni.ols <- vector(mode = "list", length = 1000)
krls.fil.div.ols <- vector(mode = "list", length = 1000)
krls.fil.uni.efa <- vector(mode = "list", length = 1000)
krls.fil.div.efa <- vector(mode = "list", length = 1000)

krls.comm.uni.ols <- vector(mode = "list", length = 1000)
krls.comm.div.ols <- vector(mode = "list", length = 1000)
krls.comm.uni.efa <- vector(mode = "list", length = 1000)
krls.comm.div.efa <- vector(mode = "list", length = 1000)

krls.chair.uni.ols <- vector(mode = "list", length = 1000)
krls.chair.div.ols <- vector(mode = "list", length = 1000)
krls.chair.uni.efa <- vector(mode = "list", length = 1000)
krls.chair.div.efa <- vector(mode = "list", length = 1000)

uni.median.frame.ols <- NULL
div.median.frame.ols <- NULL
uni.median.frame.efa <- NULL
div.median.frame.efa <- NULL

uni.fil.frame.ols <- NULL
div.fil.frame.ols <- NULL
uni.fil.frame.efa <- NULL
div.fil.frame.efa <- NULL

uni.comm.frame.ols <- NULL
div.comm.frame.ols <- NULL
uni.comm.frame.efa <- NULL
div.comm.frame.efa <- NULL

uni.chair.frame.ols <- NULL
div.chair.frame.ols <- NULL
uni.chair.frame.efa <- NULL
div.chair.frame.efa <- NULL

for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.median.uni.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                   X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol), 
                              select = c(fealty.ols.foo, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                   print.level = 0)
}

saveRDS(krls.median.uni.ols, "KRLS-Median-Unified-OLS-Posterior-Policy.rds")
rm(krls.median.uni.ols)
rm(repfile_foo)



for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.fil.uni.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                   X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol), 
                                              select = c(fealty.ols.foo, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                   print.level = 0)
}

saveRDS(krls.fil.uni.ols, "KRLS-Filibuster-Unified-OLS-Posterior-Policy.rds")
rm(krls.fil.uni.ols)
rm(repfile_foo)

 
for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.comm.uni.ols[[i]] <- krls(y = repfile_foo$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol) & !is.na(repfile$zprescommdist), 
                                           select = c(fealty.ols.foo, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                print.level = 0)
  }

saveRDS(krls.comm.uni.ols, "KRLS-Committee-Unified-OLS-Posterior-Policy.rds")
rm(krls.comm.uni.ols)
rm(repfile_foo)


for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.chair.uni.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                 X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol)  & !is.na(repfile$zpreschairdist), 
                                            select = c(fealty.ols.foo, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                 print.level = 0)
}

saveRDS(krls.chair.uni.ols, "KRLS-Chair-Unified-OLS-Posterior-Policy.rds")
rm(krls.chair.uni.ols)
rm(repfile_foo)


for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.median.div.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                   X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol), 
                                              select = c(fealty.ols.foo, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                   print.level = 0)
  }

saveRDS(krls.median.div.ols, "KRLS-Median-Divided-OLS-Posterior-Policy.rds")
rm(krls.median.div.ols)
rm(repfile_foo)


for(i in 1:1000){
  
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.fil.div.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol), 
                                           select = c(fealty.ols.foo, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                print.level = 0)
}

saveRDS(krls.fil.div.ols, "KRLS-Filibuster-Divided-OLS-Posterior-Policy.rds")
rm(krls.fil.div.ols)
rm(repfile_foo)



for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.comm.div.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                 X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol) & !is.na(repfile$zprescommdist), 
                                            select = c(fealty.ols.foo, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                 print.level = 0)
                                 }

saveRDS(krls.comm.div.ols, "KRLS-Committee-Divided-OLS-Posterior-Policy.rds")
rm(krls.comm.div.ols)
rm(repfile_foo)

  
  
for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.ols.foo <- eval(parse(text = paste('repfile$fealty.ols.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.chair.div.ols[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                  X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol)  & !is.na(repfile$zpreschairdist), 
                                             select = c(fealty.ols.foo, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                  print.level = 0)

}

saveRDS(krls.chair.div.ols, "KRLS-Chair-Divided-OLS-Posterior-Policy.rds")
rm(krls.chair.div.ols)
rm(repfile_foo)




for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.median.uni.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                   X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol), 
                                              select = c(fealty.efa.foo, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                   print.level = 0)
}

saveRDS(krls.median.uni.efa, "KRLS-Median-Unified-EFA-Posterior-Policy.rds")
rm(krls.median.uni.efa)
rm(repfile_foo)



for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.fil.uni.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol))], 
                                X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol), 
                                           select = c(fealty.efa.foo, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                print.level = 0)
}

saveRDS(krls.fil.uni.efa, "KRLS-Filibuster-Unified-EFA-Posterior-Policy.rds")
rm(krls.fil.uni.efa)
rm(repfile_foo)


for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.comm.uni.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                 X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol) & !is.na(repfile$zprescommdist), 
                                            select = c(fealty.efa.foo, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                 print.level = 0)
}

saveRDS(krls.comm.uni.efa, "KRLS-Committee-Unified-EFA-Posterior-Policy.rds")
rm(krls.comm.uni.efa)
rm(repfile_foo)


for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.chair.uni.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                  X = subset(repfile_foo, dividedpressenate == 0 & !is.na(presallyagencyideol) & !is.na(repfile$zpreschairdist), 
                                             select = c(fealty.efa.foo, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                  print.level = 0)
}

saveRDS(krls.chair.uni.efa, "KRLS-Chair-Unified-EFA-Posterior-Policy.rds")
rm(krls.chair.uni.efa)
rm(repfile_foo)


for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.median.div.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                   X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol), 
                                              select = c(fealty.efa.foo, zpressendist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                   print.level = 0)
}

saveRDS(krls.median.div.efa, "KRLS-Median-Divided-EFA-Posterior-Policy.rds")
rm(krls.median.div.efa)
rm(repfile_foo)


for(i in 1:1000){
  
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.fil.div.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol))], 
                                X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol), 
                                           select = c(fealty.efa.foo, zpresfildist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                print.level = 0)
}

saveRDS(krls.fil.div.efa, "KRLS-Filibuster-Divided-EFA-Posterior-Policy.rds")
rm(krls.fil.div.efa)
rm(repfile_foo)



for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.comm.div.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist))], 
                                 X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol) & !is.na(repfile$zprescommdist), 
                                            select = c(fealty.efa.foo, zprescommdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                 print.level = 0)
}

saveRDS(krls.comm.div.efa, "KRLS-Committee-Divided-EFA-Posterior-Policy.rds")
rm(krls.comm.div.efa)
rm(repfile_foo)



for(i in 1:1000){
  repfile_foo <- repfile
  repfile_foo$fealty.efa.foo <- eval(parse(text = paste('repfile$fealty.efa.',i,sep = "")))
  repfile_foo$policy.foo <- eval(parse(text = paste('repfile$policy.',i,sep = "")))
  
  krls.chair.div.efa[[i]] <- krls(y = repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist))], 
                                  X = subset(repfile_foo, dividedpressenate == 1 & !is.na(presallyagencyideol) & !is.na(repfile$zpreschairdist), 
                                             select = c(fealty.efa.foo, zpreschairdist, zpolarization, congress, toplevel2, presalignedagency, presopposedagency, soucountagency1, approval, policy.foo)),
                                  print.level = 0)
                                  
}

saveRDS(krls.chair.div.efa, "KRLS-Chair-Divided-EFA-Posterior-Policy.rds")
rm(krls.chair.div.efa)
rm(repfile_foo)



krls.median.uni.ols <- readRDS("KRLS-Median-Unified-OLS-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.median.plot.ols <- qplot(x = repfile$zpressendist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol)], 
                    y = krls.median.uni.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  
  uni.median.build.ols <- ggplot_build(uni.median.plot.ols)$data[[2]]
  uni.median.frame.ols <- rbind(uni.median.frame.ols,
                                data.frame(Divergence = uni.median.build.ols$x,
                                           Derivative = uni.median.build.ols$y,
                                           Simulation = i,
                                           Party = "Unified Government",
                                           Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                           Pivot = "Senate Median"))
}

rm(krls.median.uni.ols)
  
  

krls.fil.uni.ols <- readRDS("KRLS-Filibuster-Unified-OLS-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.fil.plot.ols <- qplot(x = repfile$zpresfildist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol)], 
                               y = krls.fil.uni.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  
  uni.fil.build.ols <- ggplot_build(uni.fil.plot.ols)$data[[2]]
  uni.fil.frame.ols <- rbind(uni.fil.frame.ols,
                             data.frame(Divergence = uni.fil.build.ols$x,
                                        Derivative = uni.fil.build.ols$y,
                                        Simulation = i,
                                        Party = "Unified Government",
                                        Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                        Pivot = "Filibuster Pivot"))
}

rm(krls.fil.uni.ols)

  


krls.comm.uni.ols <- readRDS("KRLS-Committee-Unified-OLS-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.comm.plot.ols <- qplot(x = repfile$zprescommdist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist)], 
                            y = krls.comm.uni.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  uni.comm.build.ols <- ggplot_build(uni.comm.plot.ols)$data[[2]]
  uni.comm.frame.ols <- rbind(uni.comm.frame.ols,
                              data.frame(Divergence = uni.comm.build.ols$x,
                                         Derivative = uni.comm.build.ols$y,
                                         Simulation = i,
                                         Party = "Unified Government",
                                         Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                         Pivot = "Committee Median"))
}
rm(krls.comm.uni.ols)

  
krls.chair.uni.ols <- readRDS("KRLS-Chair-Unified-OLS-Posterior-Policy.rds")
for(i in 1:1000){
  uni.chair.plot.ols <- qplot(x = repfile$zpreschairdist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist)], 
                             y = krls.chair.uni.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  uni.chair.build.ols <- ggplot_build(uni.chair.plot.ols)$data[[2]]
  uni.chair.frame.ols <- rbind(uni.chair.frame.ols,
                               data.frame(Divergence = uni.chair.build.ols$x,
                                          Derivative = uni.chair.build.ols$y,
                                          Simulation = i,
                                          Party = "Unified Government",
                                          Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                          Pivot = "Committee Chair"))
}
rm(krls.chair.uni.ols)

  
krls.median.div.ols <- readRDS("KRLS-Median-Divided-OLS-Posterior-Policy.rds")
for(i in 1:1000){
  div.median.plot.ols <- qplot(x = repfile$zpressendist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol)], 
                               y = krls.median.div.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.median.build.ols <- ggplot_build(div.median.plot.ols)$data[[2]]
  div.median.frame.ols <- rbind(div.median.frame.ols,
                                data.frame(Divergence = div.median.build.ols$x,
                                           Derivative = div.median.build.ols$y,
                                           Simulation = i,
                                           Party = "Divided Government",
                                           Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                           Pivot = "Senate Median"))
}
rm(krls.median.div.ols)

  
krls.fil.div.ols <- readRDS("KRLS-Filibuster-Divided-OLS-Posterior-Policy.rds")
for(i in 1:1000){
  div.fil.plot.ols <- qplot(x = repfile$zpresfildist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol)], 
                            y = krls.fil.div.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.fil.build.ols <- ggplot_build(div.fil.plot.ols)$data[[2]]
  div.fil.frame.ols <- rbind(div.fil.frame.ols,
                             data.frame(Divergence = div.fil.build.ols$x,
                                        Derivative = div.fil.build.ols$y,
                                        Simulation = i,
                                        Party = "Divided Government",
                                        Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                        Pivot = "Filibuster Pivot"))
}
rm(krls.fil.div.ols)

 
krls.comm.div.ols <- readRDS("KRLS-Committee-Divided-OLS-Posterior-Policy.rds")
for(i in 1:1000){
  div.comm.plot.ols <- qplot(x = repfile$zprescommdist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist)], 
                             y = krls.comm.div.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.comm.build.ols <- ggplot_build(div.comm.plot.ols)$data[[2]]
  div.comm.frame.ols <- rbind(div.comm.frame.ols,
                              data.frame(Divergence = div.comm.build.ols$x,
                                         Derivative = div.comm.build.ols$y,
                                         Simulation = i,
                                         Party = "Divided Government",
                                         Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                         Pivot = "Committee Median"))
}
rm(krls.comm.div.ols)


krls.chair.div.ols <- readRDS("KRLS-Chair-Divided-OLS-Posterior-Policy.rds")
for(i in 1:1000){
  div.chair.plot.ols <- qplot(x = repfile$zpreschairdist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist)], 
                              y = krls.chair.div.ols[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.chair.build.ols <- ggplot_build(div.chair.plot.ols)$data[[2]]
  div.chair.frame.ols <- rbind(div.chair.frame.ols,
                               data.frame(Divergence = div.chair.build.ols$x,
                                          Derivative = div.chair.build.ols$y,
                                          Simulation = i,
                                          Party = "Divided Government",
                                          Estimator = "Regression-Based\n(Original Krause & O'Connell Scores)",
                                          Pivot = "Committee Chair"))
}
rm(krls.chair.div.ols)

 





krls.median.uni.efa <- readRDS("KRLS-Median-Unified-EFA-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.median.plot.efa <- qplot(x = repfile$zpressendist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol)], 
                               y = krls.median.uni.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  
  uni.median.build.efa <- ggplot_build(uni.median.plot.efa)$data[[2]]
  uni.median.frame.efa <- rbind(uni.median.frame.efa,
                                data.frame(Divergence = uni.median.build.efa$x,
                                           Derivative = uni.median.build.efa$y,
                                           Simulation = i,
                                           Party = "Unified Government",
                                           Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                           Pivot = "Senate Median"))
}

rm(krls.median.uni.efa)



krls.fil.uni.efa <- readRDS("KRLS-Filibuster-Unified-EFA-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.fil.plot.efa <- qplot(x = repfile$zpresfildist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol)], 
                            y = krls.fil.uni.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  
  uni.fil.build.efa <- ggplot_build(uni.fil.plot.efa)$data[[2]]
  uni.fil.frame.efa <- rbind(uni.fil.frame.efa,
                             data.frame(Divergence = uni.fil.build.efa$x,
                                        Derivative = uni.fil.build.efa$y,
                                        Simulation = i,
                                        Party = "Unified Government",
                                        Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                        Pivot = "Filibuster Pivot"))
}

rm(krls.fil.uni.efa)




krls.comm.uni.efa <- readRDS("KRLS-Committee-Unified-EFA-Posterior-Policy.rds")

for(i in 1:1000){  
  uni.comm.plot.efa <- qplot(x = repfile$zprescommdist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist)], 
                             y = krls.comm.uni.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  uni.comm.build.efa <- ggplot_build(uni.comm.plot.efa)$data[[2]]
  uni.comm.frame.efa <- rbind(uni.comm.frame.efa,
                              data.frame(Divergence = uni.comm.build.efa$x,
                                         Derivative = uni.comm.build.efa$y,
                                         Simulation = i,
                                         Party = "Unified Government",
                                         Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                         Pivot = "Committee Median"))
}
rm(krls.comm.uni.efa)


krls.chair.uni.efa <- readRDS("KRLS-Chair-Unified-EFA-Posterior-Policy.rds")
for(i in 1:1000){
  uni.chair.plot.efa <- qplot(x = repfile$zpreschairdist[repfile$dividedpressenate == 0 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist)], 
                              y = krls.chair.uni.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  uni.chair.build.efa <- ggplot_build(uni.chair.plot.efa)$data[[2]]
  uni.chair.frame.efa <- rbind(uni.chair.frame.efa,
                               data.frame(Divergence = uni.chair.build.efa$x,
                                          Derivative = uni.chair.build.efa$y,
                                          Simulation = i,
                                          Party = "Unified Government",
                                          Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                          Pivot = "Committee Chair"))
}
rm(krls.chair.uni.efa)


krls.median.div.efa <- readRDS("KRLS-Median-Divided-EFA-Posterior-Policy.rds")
for(i in 1:1000){
  div.median.plot.efa <- qplot(x = repfile$zpressendist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol)], 
                               y = krls.median.div.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.median.build.efa <- ggplot_build(div.median.plot.efa)$data[[2]]
  div.median.frame.efa <- rbind(div.median.frame.efa,
                                data.frame(Divergence = div.median.build.efa$x,
                                           Derivative = div.median.build.efa$y,
                                           Simulation = i,
                                           Party = "Divided Government",
                                           Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                           Pivot = "Senate Median"))
}
rm(krls.median.div.efa)


krls.fil.div.efa <- readRDS("KRLS-Filibuster-Divided-EFA-Posterior-Policy.rds")
for(i in 1:1000){
  div.fil.plot.efa <- qplot(x = repfile$zpresfildist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol)], 
                            y = krls.fil.div.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.fil.build.efa <- ggplot_build(div.fil.plot.efa)$data[[2]]
  div.fil.frame.efa <- rbind(div.fil.frame.efa,
                             data.frame(Divergence = div.fil.build.efa$x,
                                        Derivative = div.fil.build.efa$y,
                                        Simulation = i,
                                        Party = "Divided Government",
                                        Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                        Pivot = "Filibuster Pivot"))
}
rm(krls.fil.div.efa)


krls.comm.div.efa <- readRDS("KRLS-Committee-Divided-EFA-Posterior-Policy.rds")
for(i in 1:1000){
  div.comm.plot.efa <- qplot(x = repfile$zprescommdist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zprescommdist)], 
                             y = krls.comm.div.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.comm.build.efa <- ggplot_build(div.comm.plot.efa)$data[[2]]
  div.comm.frame.efa <- rbind(div.comm.frame.efa,
                              data.frame(Divergence = div.comm.build.efa$x,
                                         Derivative = div.comm.build.efa$y,
                                         Simulation = i,
                                         Party = "Divided Government",
                                         Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                         Pivot = "Committee Median"))
}
rm(krls.comm.div.efa)


krls.chair.div.efa <- readRDS("KRLS-Chair-Divided-EFA-Posterior-Policy.rds")
for(i in 1:1000){
  div.chair.plot.efa <- qplot(x = repfile$zpreschairdist[repfile$dividedpressenate == 1 & !is.na(repfile$presallyagencyideol) & !is.na(repfile$zpreschairdist)], 
                              y = krls.chair.div.efa[[i]]$derivatives[,1]) + 
    stat_smooth(formula = "y ~ x", method = "loess")
  div.chair.build.efa <- ggplot_build(div.chair.plot.efa)$data[[2]]
  div.chair.frame.efa <- rbind(div.chair.frame.efa,
                               data.frame(Divergence = div.chair.build.efa$x,
                                          Derivative = div.chair.build.efa$y,
                                          Simulation = i,
                                          Party = "Divided Government",
                                          Estimator = "Exploratory Factor Analysis\n(Two-Factor)",
                                          Pivot = "Committee Chair"))
}
rm(krls.chair.div.efa)



krls.median.frame <- rbind(uni.median.frame.ols,
                           div.median.frame.ols,
                           uni.median.frame.efa,
                           div.median.frame.efa)

krls.fil.frame <- rbind(uni.fil.frame.ols,
                        div.fil.frame.ols,
                        uni.fil.frame.efa,
                        div.fil.frame.efa)

krls.comm.frame <- rbind(uni.comm.frame.ols,
                         div.comm.frame.ols,
                         uni.comm.frame.efa,
                         div.comm.frame.efa)

krls.chair.frame <- rbind(uni.chair.frame.ols,
                          div.chair.frame.ols,
                          uni.chair.frame.efa,
                          div.chair.frame.efa)


krls.median.frame$Estimator <- factor(krls.median.frame$Estimator, 
                                      levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                "Exploratory Factor Analysis\n(Two-Factor)"))

krls.fil.frame$Estimator <- factor(krls.fil.frame$Estimator, 
                                      levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                "Exploratory Factor Analysis\n(Two-Factor)"))

krls.comm.frame$Estimator <- factor(krls.comm.frame$Estimator, 
                                   levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                             "Exploratory Factor Analysis\n(Two-Factor)"))

krls.chair.frame$Estimator <- factor(krls.chair.frame$Estimator, 
                                    levels= c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                              "Exploratory Factor Analysis\n(Two-Factor)"))

krls.median.frame$Rescaled <- krls.median.frame$Divergence
krls.median.frame$Rescaled[krls.median.frame$Party == "Unified Government"] <- scales::rescale(ecdf(unique(krls.median.frame$Rescaled[krls.median.frame$Party == "Unified Government"]))(krls.median.frame$Rescaled[krls.median.frame$Party == "Unified Government"]), to = c(0,100))
krls.median.frame$Rescaled[krls.median.frame$Party == "Divided Government"] <- scales::rescale(ecdf(unique(krls.median.frame$Rescaled[krls.median.frame$Party == "Divided Government"]))(krls.median.frame$Rescaled[krls.median.frame$Party == "Divided Government"]), to = c(0,100))

krls.fil.frame$Rescaled <- krls.fil.frame$Divergence
krls.fil.frame$Rescaled[krls.fil.frame$Party == "Unified Government"] <- scales::rescale(ecdf(unique(krls.fil.frame$Rescaled[krls.fil.frame$Party == "Unified Government"]))(krls.fil.frame$Rescaled[krls.fil.frame$Party == "Unified Government"]), to = c(0,100))
krls.fil.frame$Rescaled[krls.fil.frame$Party == "Divided Government"] <- scales::rescale(ecdf(unique(krls.fil.frame$Rescaled[krls.fil.frame$Party == "Divided Government"]))(krls.fil.frame$Rescaled[krls.fil.frame$Party == "Divided Government"]), to = c(0,100))

krls.comm.frame$Rescaled <- krls.comm.frame$Divergence
krls.comm.frame$Rescaled[krls.comm.frame$Party == "Unified Government"] <- scales::rescale(ecdf(unique(krls.comm.frame$Rescaled[krls.comm.frame$Party == "Unified Government"]))(krls.comm.frame$Rescaled[krls.comm.frame$Party == "Unified Government"]), to = c(0,100))
krls.comm.frame$Rescaled[krls.comm.frame$Party == "Divided Government"] <- scales::rescale(ecdf(unique(krls.comm.frame$Rescaled[krls.comm.frame$Party == "Divided Government"]))(krls.comm.frame$Rescaled[krls.comm.frame$Party == "Divided Government"]), to = c(0,100))

krls.chair.frame$Rescaled <- krls.chair.frame$Divergence
krls.chair.frame$Rescaled[krls.chair.frame$Party == "Unified Government"] <- scales::rescale(ecdf(unique(krls.chair.frame$Rescaled[krls.chair.frame$Party == "Unified Government"]))(krls.chair.frame$Rescaled[krls.chair.frame$Party == "Unified Government"]), to = c(0,100))
krls.chair.frame$Rescaled[krls.chair.frame$Party == "Divided Government"] <- scales::rescale(ecdf(unique(krls.chair.frame$Rescaled[krls.chair.frame$Party == "Divided Government"]))(krls.chair.frame$Rescaled[krls.chair.frame$Party == "Divided Government"]), to = c(0,100))









krls.median.frame$SD_Derivative <- krls.median.frame$Derivative
krls.median.frame$SD_Derivative[krls.median.frame$Party == "Unified Government" & 
                                  krls.median.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.median.frame$Derivative[krls.median.frame$Party == "Unified Government" & 
                                 krls.median.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                        !is.na(repfile$presallyagencyideol))])
krls.median.frame$SD_Derivative[krls.median.frame$Party == "Divided Government" & 
                                  krls.median.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.median.frame$Derivative[krls.median.frame$Party == "Divided Government" & 
                                 krls.median.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                        !is.na(repfile$presallyagencyideol))])
krls.median.frame$SD_Derivative[krls.median.frame$Party == "Unified Government" & 
                                  krls.median.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.median.frame$Derivative[krls.median.frame$Party == "Unified Government" & 
                                 krls.median.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                            !is.na(repfile$presallyagencyideol))])
krls.median.frame$SD_Derivative[krls.median.frame$Party == "Divided Government" & 
                                  krls.median.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.median.frame$Derivative[krls.median.frame$Party == "Divided Government" & 
                                 krls.median.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                            !is.na(repfile$presallyagencyideol))])



krls.fil.frame$SD_Derivative <- krls.fil.frame$Derivative
krls.fil.frame$SD_Derivative[krls.fil.frame$Party == "Unified Government" & 
                               krls.fil.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.fil.frame$Derivative[krls.fil.frame$Party == "Unified Government" & 
                              krls.fil.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])
krls.fil.frame$SD_Derivative[krls.fil.frame$Party == "Divided Government" & 
                               krls.fil.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.fil.frame$Derivative[krls.fil.frame$Party == "Divided Government" & 
                              krls.fil.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                  !is.na(repfile$presallyagencyideol))])
krls.fil.frame$SD_Derivative[krls.fil.frame$Party == "Unified Government" & 
                               krls.fil.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.fil.frame$Derivative[krls.fil.frame$Party == "Unified Government" & 
                              krls.fil.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                      !is.na(repfile$presallyagencyideol))])
krls.fil.frame$SD_Derivative[krls.fil.frame$Party == "Divided Government" & 
                               krls.fil.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.fil.frame$Derivative[krls.fil.frame$Party == "Divided Government" & 
                              krls.fil.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                      !is.na(repfile$presallyagencyideol))])


krls.comm.frame$SD_Derivative <- krls.comm.frame$Derivative
krls.comm.frame$SD_Derivative[krls.comm.frame$Party == "Unified Government" & 
                                krls.comm.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.comm.frame$Derivative[krls.comm.frame$Party == "Unified Government" & 
                               krls.comm.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                    !is.na(repfile$presallyagencyideol) &
                                                                                                                                                                    !is.na(repfile$zprescommdist))])
krls.comm.frame$SD_Derivative[krls.comm.frame$Party == "Divided Government" & 
                                krls.comm.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.comm.frame$Derivative[krls.comm.frame$Party == "Divided Government" & 
                               krls.comm.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                    !is.na(repfile$presallyagencyideol) &
                                                                                                                                                                    !is.na(repfile$zprescommdist))])

krls.comm.frame$SD_Derivative[krls.comm.frame$Party == "Unified Government" & 
                                krls.comm.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.comm.frame$Derivative[krls.comm.frame$Party == "Unified Government" & 
                               krls.comm.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                        !is.na(repfile$presallyagencyideol) &
                                                                                                                                                        !is.na(repfile$zprescommdist))])
krls.comm.frame$SD_Derivative[krls.comm.frame$Party == "Divided Government" & 
                                krls.comm.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.comm.frame$Derivative[krls.comm.frame$Party == "Divided Government" & 
                               krls.comm.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                        !is.na(repfile$presallyagencyideol) &
                                                                                                                                                        !is.na(repfile$zprescommdist))])



krls.chair.frame$SD_Derivative <- krls.chair.frame$Derivative
krls.chair.frame$SD_Derivative[krls.chair.frame$Party == "Unified Government" & 
                                 krls.chair.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.chair.frame$Derivative[krls.chair.frame$Party == "Unified Government" & 
                                krls.chair.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                                      !is.na(repfile$presallyagencyideol) &
                                                                                                                                                                      !is.na(repfile$zpreschairdist))])
krls.chair.frame$SD_Derivative[krls.chair.frame$Party == "Divided Government" & 
                                 krls.chair.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"] <- 
  krls.chair.frame$Derivative[krls.chair.frame$Party == "Divided Government" & 
                                krls.chair.frame$Estimator == "Regression-Based\n(Original Krause & O'Connell Scores"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                                      !is.na(repfile$presallyagencyideol) &
                                                                                                                                                                      !is.na(repfile$zpreschairdist))])


krls.chair.frame$SD_Derivative[krls.chair.frame$Party == "Unified Government" & 
                                 krls.chair.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.chair.frame$Derivative[krls.chair.frame$Party == "Unified Government" & 
                                krls.chair.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 0 & 
                                                                                                                                                          !is.na(repfile$presallyagencyideol) &
                                                                                                                                                          !is.na(repfile$zpreschairdist))])
krls.chair.frame$SD_Derivative[krls.chair.frame$Party == "Divided Government" & 
                                 krls.chair.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"] <- 
  krls.chair.frame$Derivative[krls.chair.frame$Party == "Divided Government" & 
                                krls.chair.frame$Estimator == "Exploratory Factor Analysis\n(Two-Factor)"]/sd(repfile$zpresnomdist[which(repfile$dividedpressenate == 1 & 
                                                                                                                                                          !is.na(repfile$presallyagencyideol) &
                                                                                                                                                          !is.na(repfile$zpreschairdist))])

krls.median.frame$Party <- factor(krls.median.frame$Party, levels = c("Unified Government", "Divided Government"))
krls.fil.frame$Party <- factor(krls.fil.frame$Party, levels = c("Unified Government", "Divided Government"))
krls.comm.frame$Party <- factor(krls.comm.frame$Party, levels = c("Unified Government", "Divided Government"))
krls.chair.frame$Party <- factor(krls.chair.frame$Party, levels = c("Unified Government", "Divided Government"))



# PLOTS
krls.median.posterior.plot.small <- ggplot(subset(krls.median.frame, Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                              "Exploratory Factor Analysis\n(Two-Factor)")),
                          aes(x = Rescaled, y = SD_Derivative, group = Simulation)) + 
  geom_line(alpha = 0.025) + 
  facet_grid(Party ~ Estimator) + 
  geom_hline(yintercept = 0, lty = "dotted") +
  theme_bw() + 
  xlab('\nAbsolute President-Senate Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Estimated Marginal Effect of Fealty on President-Appointee Divergence\n(Standardized by the Standard Deviation of Divergence)\n') 

krls.fil.posterior.plot.small <- ggplot(subset(krls.fil.frame, Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                      "Exploratory Factor Analysis\n(Two-Factor)")),
                                           aes(x = Rescaled, y = SD_Derivative, group = Simulation)) + 
  geom_line(alpha = 0.025) + 
  facet_grid(Party ~ Estimator, scales = "free_y") + 
  geom_hline(yintercept = 0, lty = "dotted") +
  theme_bw() + 
  xlab('\nAbsolute President-Filibuster Pivot Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Estimated Marginal Effect of Fealty on President-Appointee Divergence\n(Standardized by the Standard Deviation of Divergence)\n') 

krls.comm.posterior.plot.small <- ggplot(subset(krls.comm.frame, Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                "Exploratory Factor Analysis\n(Two-Factor)")),
                                        aes(x = Rescaled, y = SD_Derivative, group = Simulation)) + 
  geom_line(alpha = 0.025) + 
  facet_grid(Party ~ Estimator) + 
  geom_hline(yintercept = 0, lty = "dotted") +
  theme_bw() + 
  xlab('\nAbsolute President-Committee Median Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Estimated Marginal Effect of Fealty on President-Appointee Divergence\n(Standardized by the Standard Deviation of Divergence)\n') 

krls.chair.posterior.plot.small <- ggplot(subset(krls.chair.frame, Estimator %in% c("Regression-Based\n(Original Krause & O'Connell Scores)",
                                                                                  "Exploratory Factor Analysis\n(Two-Factor)")),
                                         aes(x = Rescaled, y = SD_Derivative, group = Simulation)) + 
  geom_line(alpha = 0.025) + 
  facet_grid(Party ~ Estimator) + 
  geom_hline(yintercept = 0, lty = "dotted") +
  theme_bw() + 
  xlab('\nAbsolute President-Committee Chair Ideological Divergence\n(Percentile Conditional on Unified/Divided Status)') + 
  ylab('Estimated Marginal Effect of Fealty on President-Appointee Divergence\n(Standardized by the Standard Deviation of Divergence)\n') 



ggsave(krls.median.posterior.plot.small, file = "Figure-A1.pdf", height = 7, width = 8)
ggsave(krls.median.posterior.plot.small, file = "Figure-A1.png", height = 7, width = 8)
ggsave(krls.fil.posterior.plot.small, file = "Figure-A2.pdf", height = 7, width = 8)
ggsave(krls.fil.posterior.plot.small, file = "Figure-A2.png", height = 7, width = 8)
ggsave(krls.comm.posterior.plot.small, file = "Figure-A4.pdf", height = 7, width = 8)
ggsave(krls.comm.posterior.plot.small, file = "Figure-A4.png", height = 7, width = 8)
ggsave(krls.chair.posterior.plot.small, file = "Figure-A3.pdf",height = 7, width = 8)
ggsave(krls.chair.posterior.plot.small, file = "Figure-A3.png",height = 7, width = 8)



htmlreg(file = "Table-A11a.doc",
        list(extract.krls.pooled("KRLS-Median-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Median-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Median-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Median-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Senate Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))



htmlreg(file = "Table-A11b",
        list(extract.krls.pooled("KRLS-Filibuster-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Filibuster-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Filibuster-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Filibuster-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Filibuster Pivot Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A12b.doc",
        list(extract.krls.pooled("KRLS-Committee-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Committee-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Committee-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Committee-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Committee Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))



htmlreg(file = "Table-A12a.doc",
        list(extract.krls.pooled("KRLS-Chair-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Chair-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Chair-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.pooled("KRLS-Chair-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Committee Chair Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        stars = c(0.01, 0.05, 0.1), digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))







htmlreg(file = "Table-A13a.doc",
        list(extract.krls.quartile.pooled("KRLS-Median-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Median-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Median-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Median-Divided-EFA-Posterior-Policy.rds")),
custom.coef.names = c("Fealty (OLS)",
                      "President-Senate Median Ideological Divergence",
                      "Senate Polarization",
                      "Congress",
                      "Supervisory Position",
                      "Presidentially-Aligned Agency",
                      "Presidentially-Opposed Agency",
                      "Priority Agency",
                      "Presidential Approval",
                      "Policy Expertise",
                      "Fealty (EFA)"),
star.symbol = "", digits = 3,
custom.model.names = c("OLS-Based Scores (Unified Government)",
                       "OLS-Based Scores (Divided Government)",
                       "EFA-Based Scores (Unified Government)",
                       "EFA-Based Scores (Divided Government)"))



htmlreg(file = "Table-A13b.doc",
        list(extract.krls.quartile.pooled("KRLS-Filibuster-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Filibuster-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Filibuster-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Filibuster-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Filibuster Pivot Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))



htmlreg(file = "Table-A14b.doc",
        list(extract.krls.quartile.pooled("KRLS-Committee-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Committee-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Committee-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Committee-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Committee Median Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


htmlreg(file = "Table-A14a.doc",
        list(extract.krls.quartile.pooled("KRLS-Chair-Unified-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Chair-Divided-OLS-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Chair-Unified-EFA-Posterior-Policy.rds"),
             extract.krls.quartile.pooled("KRLS-Chair-Divided-EFA-Posterior-Policy.rds")),
        custom.coef.names = c("Fealty (OLS)",
                              "President-Committee Chair Ideological Divergence",
                              "Senate Polarization",
                              "Congress",
                              "Supervisory Position",
                              "Presidentially-Aligned Agency",
                              "Presidentially-Opposed Agency",
                              "Priority Agency",
                              "Presidential Approval",
                              "Policy Expertise",
                              "Fealty (EFA)"),
        star.symbol = "", digits = 3,
        custom.model.names = c("OLS-Based Scores (Unified Government)",
                               "OLS-Based Scores (Divided Government)",
                               "EFA-Based Scores (Unified Government)",
                               "EFA-Based Scores (Divided Government)"))


# robustness checks --- multinomial models
repfile_mult <- repfile
repfile$policy.mean <- apply(repfile[,grep("policy", colnames(repfile))],1,mean, na.rm = T)


repfile_mult$bothhigh.ols.tercile <- as.numeric(with(repfile, fealty.ols.mean >= quantile(fealty.ols.mean,c(1/3,2/3), na.rm = T)[2] & 
                                                           zpresnomdist <= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[1])) 
repfile_mult$bothlow.ols.tercile <- as.numeric(with(repfile, fealty.ols.mean <= quantile(fealty.ols.mean,c(1/3,2/3), na.rm = T)[1] & 
                                                          zpresnomdist >= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[2])) 
repfile_mult$fealhighideolow.ols.tercile <- as.numeric(with(repfile, fealty.ols.mean >= quantile(fealty.ols.mean,c(1/3,2/3), na.rm = T)[2] & 
                                                                  zpresnomdist >= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[2])) 
repfile_mult$feallowideohigh.ols.tercile <- as.numeric(with(repfile, fealty.ols.mean <= quantile(fealty.ols.mean,c(1/3,2/3), na.rm = T)[1] & 
                                                                  zpresnomdist <= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[1])) 



repfile_mult$bothhigh.efa.tercile <- as.numeric(with(repfile, fealty.efa.mean >= quantile(fealty.efa.mean,c(1/3,2/3), na.rm = T)[2] & 
                                                                   zpresnomdist <= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[1])) 
repfile_mult$bothlow.efa.tercile <- as.numeric(with(repfile, fealty.efa.mean <= quantile(fealty.efa.mean,c(1/3,2/3), na.rm = T)[1] & 
                                                                  zpresnomdist >= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[2])) 
repfile_mult$fealhighideolow.efa.tercile <- as.numeric(with(repfile, fealty.efa.mean >= quantile(fealty.efa.mean,c(1/3,2/3), na.rm = T)[2] & 
                                                                          zpresnomdist >= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[2])) 
repfile_mult$feallowideohigh.efa.tercile <- as.numeric(with(repfile, fealty.efa.mean <= quantile(fealty.efa.mean,c(1/3,2/3), na.rm = T)[1] & 
                                                                          zpresnomdist <= quantile(zpresnomdist,c(1/3,2/3), na.rm = T)[1])) 


repfile_mult$multinomialsubcomp.ols.tercile <- "Neither"
repfile_mult$multinomialsubcomp.ols.tercile[repfile_mult$bothhigh.ols.tercile == 1] <- "Both High"
repfile_mult$multinomialsubcomp.ols.tercile[repfile_mult$bothlow.ols.tercile == 1] <- "Both Low"
repfile_mult$multinomialsubcomp.ols.tercile[repfile_mult$fealhighideolow.ols.tercile == 1] <- "High Fealty, Low Shared"
repfile_mult$multinomialsubcomp.ols.tercile[repfile_mult$feallowideohigh.ols.tercile == 1] <- "Low Fealty, High Shared"
repfile_mult$multinomialsubcomp.ols.tercile <- factor(repfile_mult$multinomialsubcomp.ols.tercile,
                                                          levels = c("Neither", "High Fealty, Low Shared", "Low Fealty, High Shared",
                                                                     "Both Low", "Both High")) 


repfile_mult$multinomialsubcomp.efa.tercile <- "Neither"
repfile_mult$multinomialsubcomp.efa.tercile[repfile_mult$bothhigh.efa.tercile == 1] <- "Both High"
repfile_mult$multinomialsubcomp.efa.tercile[repfile_mult$bothlow.efa.tercile == 1] <- "Both Low"
repfile_mult$multinomialsubcomp.efa.tercile[repfile_mult$fealhighideolow.efa.tercile == 1] <- "High Fealty, Low Shared"
repfile_mult$multinomialsubcomp.efa.tercile[repfile_mult$feallowideohigh.efa.tercile == 1] <- "Low Fealty, High Shared"
repfile_mult$multinomialsubcomp.efa.tercile <- factor(repfile_mult$multinomialsubcomp.efa.tercile,
                                                                  levels = c("Neither", "High Fealty, Low Shared", "Low Fealty, High Shared",
                                                                             "Both Low", "Both High")) 



mult.ols.tercile.med.mod <- multinom(factor(multinomialsubcomp.ols.tercile) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)
mult.efa.tercile.med.mod <- multinom(factor(multinomialsubcomp.efa.tercile) ~ dividedpressenate*(zpressendist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)

mult.ols.tercile.fil.mod <- multinom(factor(multinomialsubcomp.ols.tercile) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)
mult.efa.tercile.fil.mod <- multinom(factor(multinomialsubcomp.efa.tercile) ~ dividedpressenate*(zpresfildist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)

mult.ols.tercile.comm.mod <- multinom(factor(multinomialsubcomp.ols.tercile) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)
mult.efa.tercile.comm.mod <- multinom(factor(multinomialsubcomp.efa.tercile) ~ dividedpressenate*(zprescommdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)

mult.ols.tercile.chair.mod <- multinom(factor(multinomialsubcomp.ols.tercile) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)
mult.efa.tercile.chair.mod <- multinom(factor(multinomialsubcomp.efa.tercile) ~ dividedpressenate*(zpreschairdist + zpolarization) + congress + toplevel2 + presalignedagency + presopposedagency + soucountagency1 + approval + policy.mean, repfile_mult, maxit = 1000)



htmlreg(file = "Table-A17a.doc",
        extract.multinom(mult.ols.tercile.med.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Senate Median Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Senate Median Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Senate Median Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Senate Median Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Senate Median Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Senate Median Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Senate Median Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Senate Median Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))


htmlreg(file = "Table-A19a.doc",
        extract.multinom(mult.efa.tercile.med.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Senate Median Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Senate Median Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Senate Median Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Senate Median Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Senate Median Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Senate Median Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Senate Median Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Senate Median Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))



htmlreg(file = "Table-A17b.doc",
        extract.multinom(mult.ols.tercile.fil.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Filibuster Pivot Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Filibuster Pivot Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Filibuster Pivot Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Filibuster Pivot Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))


htmlreg(file = "Table-A19b.doc",
        extract.multinom(mult.efa.tercile.fil.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Filibuster Pivot Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Filibuster Pivot Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Filibuster Pivot Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Filibuster Pivot Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Filibuster Pivot Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))



htmlreg(file = "Table-A18b.doc",
        extract.multinom(mult.ols.tercile.comm.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Committee Median Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Committee Median Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Committee Median Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Committee Median Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Committee Median Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Committee Median Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Committee Median Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Committee Median Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))



htmlreg(file = "Table-A20b.doc",
        extract.multinom(mult.efa.tercile.comm.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Committee Median Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Committee Median Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Committee Median Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Committee Median Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Committee Median Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Committee Median Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Committee Median Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Committee Median Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))




htmlreg(file = "Table-A18a.doc",
        extract.multinom(mult.ols.tercile.chair.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Committee Chair Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Committee Chair Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Committee Chair Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Committee Chair Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Committee Chair Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Committee Chair Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Committee Chair Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Committee Chair Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))



htmlreg(file = "Table-A20a.doc",
        extract.multinom(mult.efa.tercile.chair.mod), digits = 3, stars = c(0.01, 0.05, 0.1), 
        custom.coef.names = c("High Fealty, Low Shared: Constant",
                              "High Fealty, Low Shared: Divided Government",
                              "High Fealty, Low Shared: President-Committee Chair Ideological Divergence",
                              "High Fealty, Low Shared: Senate Polarization",
                              "High Fealty, Low Shared: Congress",
                              "High Fealty, Low Shared: Supervisory Position",
                              "High Fealty, Low Shared: Presidentially-Aligned Agency",
                              "High Fealty, Low Shared: Presidentially-Opposed Agency",
                              "High Fealty, Low Shared: Priority Agency",
                              "High Fealty, Low Shared: Presidential Approval",
                              "High Fealty, Low Shared: Policy Expertise",
                              "High Fealty, Low Shared: President-Committee Chair Ideological Divergence x Divided Government",
                              "High Fealty, Low Shared: Senate Polarization x Divided Government",
                              "Low Fealty, High Shared: Constant",
                              "Low Fealty, High Shared: Divided Government",
                              "Low Fealty, High Shared: President-Committee Chair Ideological Divergence",
                              "Low Fealty, High Shared: Senate Polarization",
                              "Low Fealty, High Shared: Congress",
                              "Low Fealty, High Shared: Supervisory Position",
                              "Low Fealty, High Shared: Presidentially-Aligned Agency",
                              "Low Fealty, High Shared: Presidentially-Opposed Agency",
                              "Low Fealty, High Shared: Priority Agency",
                              "Low Fealty, High Shared: Presidential Approval",
                              "Low Fealty, High Shared: Policy Expertise",
                              "Low Fealty, High Shared: President-Committee Chair Ideological Divergence x Divided Government",
                              "Low Fealty, High Shared: Senate Polarization x Divided Government",
                              "Both Low: Constant",
                              "Both Low: Divided Government",
                              "Both Low: President-Committee Chair Ideological Divergence",
                              "Both Low: Senate Polarization",
                              "Both Low: Congress",
                              "Both Low: Supervisory Position",
                              "Both Low: Presidentially-Aligned Agency",
                              "Both Low: Presidentially-Opposed Agency",
                              "Both Low: Priority Agency",
                              "Both Low: Presidential Approval",
                              "Both Low: Policy Expertise",
                              "Both Low: President-Committee Chair Ideological Divergence x Divided Government",
                              "Both Low: Senate Polarization x Divided Government",
                              "Both High: Constant",
                              "Both High: Divided Government",
                              "Both High: President-Committee Chair Ideological Divergence",
                              "Both High: Senate Polarization",
                              "Both High: Congress",
                              "Both High: Supervisory Position",
                              "Both High: Presidentially-Aligned Agency",
                              "Both High: Presidentially-Opposed Agency",
                              "Both High: Priority Agency",
                              "Both High: Presidential Approval",
                              "Both High: Policy Expertise",
                              "Both High: President-Committee Chair Ideological Divergence x Divided Government",
                              "Both High: Senate Polarization x Divided Government"),
        reorder.coef = c(c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         13 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         26 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1), 
                         39 + c(3, 4, 2, 12, 13, 7, 8, 6, 9, 10, 11, 5, 1)))








### checking unconfirmed nominees
bcj_data_unconfirmed <- read.csv("SenConfNominees.csv")

unconfirmed.noms <- readxl::read_excel("Unconfirmed Nominees.02-05-2021.1987-2008.GREEN SHADED.xlsx")
unconfirmed.noms <- subset(unconfirmed.noms, select = c("NOMINEE NAME",  "NOMYEAR",
                                                        "confirmbinary", "AGENCY NAME", "POSITION",
                                                        "O-K Sample", "PN#"))
colnames(unconfirmed.noms) <- c("name", "nomyear", "confirmed", "agency", "position", "oksample", "nomination")
unconfirmed.noms <- subset(unconfirmed.noms, oksample == 3)
unconfirmed.noms <- merge(unconfirmed.noms, bcj_data_unconfirmed, by = "nomination")

# t-test of mean cfscores and mean differences
t.test(unconfirmed.noms$cfscore, repfile$cfscore)
t.test(abs(unconfirmed.noms$pres.ip - unconfirmed.noms$cfscore), repfile$presagencyleaderabsdist)

# kolmogorov-smirnov test of distributions of cfscores as well as differences
ks.test(unconfirmed.noms$cfscore, repfile$cfscore)
ks.test(abs(unconfirmed.noms$pres.ip - unconfirmed.noms$cfscore), repfile$presagencyleaderabsdist)




